﻿//#undef MySql
//#define MSSql
#define MySql


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///using System.Data.SqlClient;
using System.Text.RegularExpressions;

///using MySql.Data.MySqlClient;

namespace ukeasbjWeb
{
    public partial class ContractEdit : Bonus
    {
        
        //合同主键
        string sSeries_No;

        protected void Page_Load(object sender, EventArgs e)
        {

            // 在此处放置用户代码以初始化页面
            Common_SXD.Is_LongIn(Response, Session, Request);

            if(!IsPostBack)
              {	
                // 载入学生类别数据，绑定到 Drop_C_Student_Type 中
                string sSql = "select * from Student_Type where Is_Active = 1 order by Is_Active DESC, Code_Student_Type asc";
                Common_SXD.Init_DropDownList(Drop_C_Student_Type, "Student_Type", sSql);

                /// 载入留学目的地数据，绑定到 Drop_Destination_OS 中
                string sMySql = "select * from Destinations_OS order by Code_Destinations_OS asc";
                Common_SXD.Init_DropDownList(Drop_Destinations_OS, "Destinations_OS", sMySql);
                
                Common_SXD.Init_YearMonth_Start(Drop_YearMonth_Start);
 
              }
                
            ///////////// 读出合同主键
            sSeries_No = Request["Series_No"];
            Session["Flag"] = sSeries_No;
            ///////////// 分离加在合同主键前部的控制字符
            Regex NotEditFirstPayment = new Regex("([a-zA-Z_]{1,}):([0-9]{1,})");
            Regex NewOneFirstPayment = new Regex("(NewOne)");
            Regex EditFirstPayment = new Regex("([0-9]{1,})");
            string[] temp;

            if (NotEditFirstPayment.IsMatch(sSeries_No))
            {
                temp = NotEditFirstPayment.Split(sSeries_No);
                if (temp[1] == "ReadOnly")
                {// 只读方式读取合同数据
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                        Init_ReadOnly();
                    Label_Msg.Text = sSeries_No;
                    /// 初始化更换顾问、文案网页的链接    
                    ///Common_SXD.Init_Replace_C_W(Table_Replace_C_W, Label_Msg.Text.Trim());
                    return;
                }
                else if (temp[1] == "EditContractSecondPay")
                {// 
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                        Init_EditContractSecondPay();

                    Label_Msg.Text = sSeries_No;
                    /// 初始化更换顾问、文案网页的链接    
                    ///Common_SXD.Init_Replace_C_W(Table_Replace_C_W, Label_Msg.Text.Trim());
                    return;
                }
                else if (temp[1] == "CheckContractSecondPay")
                {
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                        Init_CheckContractSecondPay();
                    Label_Msg.Text = sSeries_No;
                    /// 初始化更换顾问、文案网页的链接    
                    ///Common_SXD.Init_Replace_C_W(Table_Replace_C_W, Label_Msg.Text.Trim());
                    return;

                }
                else if (temp[1] == "CheckContractFirstPay")
                {
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                        Init_CheckContractFirstPay();
                    Label_Msg.Text = sSeries_No;
                    /// 初始化更换顾问、文案网页的链接    
                    ///Common_SXD.Init_Replace_C_W(Table_Replace_C_W, Label_Msg.Text.Trim());
                    return;

                }
                else if (temp[1] == "CheckFinishedTerminationRefund")
                {
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                        //	Init_CheckContractFirstPay();
                        Init_CheckFinishedTerminationRefund();
                    Label_Msg.Text = sSeries_No;
                    /// 初始化更换顾问、文案网页的链接    
                    ///Common_SXD.Init_Replace_C_W(Table_Replace_C_W, Label_Msg.Text.Trim());
                    return;

                }

            }

            if (!IsPostBack)
            {
 
                 if (NewOneFirstPayment.IsMatch(sSeries_No))
                {
                    Label_Msg.Text = sSeries_No;
                    Init_NewOne(); //初始化：添加新数据页面（第一次付款数据）
                    /// 初始化更换顾问、文案网页的链接    
                    ///Common_SXD.Init_Replace_C_W(Table_Replace_C_W, Label_Msg.Text.Trim());
                    return;
                }
                if (EditFirstPayment.IsMatch(sSeries_No))
                {// 初始化：修改第一次付款数据
                    Label_Msg.Text = sSeries_No;
                    Init_EditContractFirstPay();
                }
            }
            Label_Msg.Text = sSeries_No;
            /// 初始化更换顾问、文案网页的链接    
            ///Common_SXD.Init_Replace_C_W(Table_Replace_C_W, Label_Msg.Text.Trim());

        }

        protected void Bt_OK_Click(object sender, EventArgs e)
        {
            ///Func eFunctions = Get_Function(Session["Flag"].ToString().Trim());
            switch (Get_Function(Session["Flag"].ToString().Trim()))
            {
                case Func.NewOne: 	// 添加一个新的记录
                    // 判断当前操作的“上月锁定状态”
                    if (Common_SXD.IsLock_LockDay_LastMonth(TextBox_Date_First_Receipt, Response))
                        break;
                    if (Common_SXD.IsLock_LockDay_LastMonth(TextBox_Date_Second_Receipt, Response))
                        break;
                    
                    Insert_NewOne();
                    break;

                case Func.EditContractFirstPay:		// 修改一期付款
                
                    Update_Contract();
                    //Init_EditContractFirstPay();
                    break;

                case Func.EditContractSecondPay: // 二期付/执行情况
              
                    Update_Contract();
                    Init_EditContractSecondPay();
                    break;

                case Func.CheckContractFirstPay:  // 确认一期款
                    // 已经结案的合同不能确认一期款
                    if ( (TextBox_Date_Completion_Contract.Text.Length > 0) )
                        if((Convert.ToDateTime(TextBox_Date_Completion_Contract.Text) >= Convert.ToDateTime("1930-1-1") ))
                            Response.Write("<li>已经结案的合同不能确认一期款</li>");
                        else
                            Update_Contract();
                    else
                        Update_Contract();
                    //Init_CheckContractFirstPay();
                    break;

                case Func.CheckContractSecondPay: // 确认二期款
                    if ((TextBox_Date_Completion_Contract.Text.Length > 0))
                        if ((Convert.ToDateTime(TextBox_Date_Completion_Contract.Text) >= Convert.ToDateTime("1930-1-1")))
                            Response.Write("<li>已经结案的合同不能确认二期款</li>");
                        else
                        {
                            Update_Contract();
                            //Init_CheckContractSecondPay();
                        }
                    else
                    {
                        Update_Contract();
                        //Init_CheckContractSecondPay();
                    }
                    Init_CheckContractSecondPay();
                    break;

                case Func.CheckFinishedTerminationRefund:
                    //Check_FinishedTerminationRefund();
                    Update_Contract();
                    //Init_CheckFinishedTerminationRefund();
                    break;

                case Func.ReadOnly:
                    if ( !Is_SuperUser(false))//Session["Email"].ToString().Trim() != "jianwei_rong")
                        break;
                    else
                        Update_Contract();
                    //Init_ReadOnly();
                    break;
                default:
                    break;

            }

        }

        //public enum Func
        private enum Func
        {
            EditContractFirstPay,
            NewOne,
            ReadOnly,
            EditContractSecondPay,
            CheckContractFirstPay,
            CheckContractSecondPay,
            CheckFinishedTerminationRefund
        }
        //		public Func eFunctions;

        /// <summary>
        /// 读取功能标识
        /// </summary>
        private Func Get_Function(string strFunction)
        {
            Regex NotEditFirstPayment = new Regex("([a-zA-Z_]{1,}):([0-9]{1,})");
            Regex NewOneFirstPayment = new Regex("(NewOne)");
            Regex EditFirstPayment = new Regex("([0-9]{1,})");
            string[] temp;

            if (NotEditFirstPayment.IsMatch(strFunction))
            {
                temp = NotEditFirstPayment.Split(strFunction);
                if (temp[1] == "ReadOnly")
                {// 只读方式读取合同数据
                    return Func.ReadOnly;
                }
                else if (temp[1] == "EditContractSecondPay")
                {// 
                    return Func.EditContractSecondPay;
                }
                else if (temp[1] == "CheckContractSecondPay")
                {
                    return Func.CheckContractSecondPay;
                }
                else if (temp[1] == "CheckContractFirstPay")
                {
                    return Func.CheckContractFirstPay;
                }
                else if (temp[1] == "CheckFinishedTerminationRefund")
                {
                    return Func.CheckFinishedTerminationRefund;
                }
            }

            if (NewOneFirstPayment.IsMatch(strFunction))
            {
                return Func.NewOne;
            }
            if (EditFirstPayment.IsMatch(strFunction))
            {
                return Func.EditContractFirstPay;
            }

            return Func.EditContractFirstPay;
        }

        /// <summary>
        /// Drop_Counsellor 控件初始化 
        /// </summary>
        private void InitializeDrop_Counsellor(string sOffice)
        {
            ///SqlConnection sqlCnn = new SqlConnection(strCnn);
            // 载顾问列表，绑定到 Drop_Counsellor 中
            string sSql;
                
                    ///sSql = "select * from Employees where ( office like '";
                    sSql = "select C_N_Employee, CONCAT(office, Code_Employee) as Code_Employee from Employees where  office like '";


                    sSql += sOffice;
                    sSql += "' and ( Is_Counsellor = 1  and Is_Active = 1) or C_N_Employee like '?' order by Code_Employee asc";

            

            Common_SXD.Init_DropDownList(Drop_Counsellor, "Employees", sSql);
            ///Common_SXD.Init_DropDownList(Drop_Net_Applicant_US, "Employees", sSql);
            ///Common_SXD.Init_DropDownList(Drop_After_Visa_US, "Employees", sSql);

        }

        /// <summary>
        /// Drop_Writer 控件初始化 
        /// Drop_Net_Applicant_US 控件初始化 
        /// Drop_After_Visa_US r控件初始化 
        /// </summary>
        private void InitializeDrop_Writer(string sOffice)
        {
            ///SqlConnection sqlCnn = new SqlConnection(strCnn);
            // 载文案列表，绑定到 Drop_Writer 中
            string sSql;
            ///string temp = Session["Office"].ToString().Trim();
            switch (Session["Office"].ToString().Trim())
            {
                // 上海文案可以配合以下办公室工作
              
                case "宁波":
                case "武汉":
                case "南京":
                case "成都":
                case "青岛":
                case "重庆":
                case "北京":
                case "杭州":
                case "广州":
                case "西安":
                    sSql = "select C_N_Employee, CONCAT(office, Code_Employee) as Code_Employee from Employees where ( office like '";
                    sSql += sOffice;
                    sSql += "' and (Is_Writer = 1 or Is_Counsellor = 1 ) and Is_Active = 1) or  ";
                    sSql += " ( Office like '上海' and Is_Writer = 1 and Is_Active = 1) or ";
                    sSql += "C_N_Employee like '?' order by Office, Code_Employee asc";

                    break;
                default:
                    ///sSql = "select * from Employees where ( office like '";
                    sSql = "select C_N_Employee, CONCAT(office, Code_Employee) as Code_Employee from Employees where ( office like '";
                    
                    
                    sSql += sOffice;
                    sSql += "' and (Is_Writer = 1 or Is_Counsellor = 1 ) and Is_Active = 1) or C_N_Employee like '?' order by Code_Employee asc";
                    
                    break;

            }
           
            Common_SXD.Init_DropDownList(Drop_Writer, "Employees", sSql);
            Common_SXD.Init_DropDownList(Drop_Net_Applicant_US, "Employees", sSql);
            Common_SXD.Init_DropDownList(Drop_After_Visa_US, "Employees", sSql);

        }

        /// <summary>
        ///  初始化网页显示控件，新添加的合同数据或者一期付款数据。
        /// </summary>
        private void InitControls_NewOne_FirstPay()
        {
            CheckBox_Is_New.Enabled = false;
            CheckBox_Deduct_FreeService.Enabled = false;

            TextBox_Counsellor.Enabled = false;
            TextBox_Writer.Enabled = false;
            TextBox_YearMonth_Start.Enabled = false; 
            TextBox_C_Student_Type.Enabled = false; 
            TextBox_After_Visa_US.Enabled = false;
            TextBox_Net_Applicant_US.Enabled = false;


            TextBox_Date_First_Payment.Enabled = false;
            TextBox_Date_Second_Payment.Enabled = false;
            TextBox_Date_Completion_Offer.Enabled = false;
            TextBox_Date_Completion_Offer_US.Enabled = false;
            TextBox_Date_Application_Visa.Enabled = false;
            TextBox_Date_Completion_Contract.Enabled = false;
            TextBox_Date_Termination_Refund.Enabled = false;

            TextBox_Date_Return_OriginalContract.Enabled = false;
            
            TextBox_Date_Finished_Termination_Refund.Enabled = false;

            TextBox_Ref_Cash_No.Enabled = false;
            TextBox_Office.Enabled = false;
            TextBox_Termination_Refund.Enabled = false;

            CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
            TextBox_Add_Notes.Enabled = false;

            

            //			InitializeDrop_Writer(TextBox_Office.Text);
        }

        /// <summary>
        ///  初始化：第一次付款的新数据。为修改“未确认新数据”做准备。
        /// </summary>
        private void Init_EditContractFirstPay()
        {
            InitControls_NewOne_FirstPay();
            ///张玉稳可以修改一期款日期、新数据标志。
            ///
            if ( Session["Email"].ToString().ToLower().Trim() == "yuwen_zhang")
            {
                TextBox_Date_First_Payment.Enabled = true;
                CheckBox_Is_New.Enabled = true;
            }
            /*
            SqlConnection sqlCnn = new SqlConnection(strCnn);
            // 根据传入的合同编号，生成查询 SQL 语句
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            SqlDataAdapter sqlDA = new SqlDataAdapter(sSql, sqlCnn);
            sqlDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            DataSet bsDataSet = new DataSet();
            sqlDA.Fill(bsDataSet, "Contract");
            */

            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            DataSet bsDataSet = Init_DataSet("Contract", sSql);
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行
                // 显示用户信息
                TextBox_Office.Text = rowUser["Office"].ToString().Trim();
                InitializeDrop_Counsellor(TextBox_Office.Text);
                InitializeDrop_Writer(TextBox_Office.Text);

                TextBox_Counsellor.Text = rowUser["Counsellor"].ToString().Trim();
                TextBox_Writer.Text = rowUser["Writer"].ToString().Trim();  
                TextBox_YearMonth_Start.Text = rowUser["YearMonth_Start"].ToString().Trim();
                TextBox_C_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();
                TextBox_After_Visa_US.Text = rowUser["After_Visa_US"].ToString().Trim();
                TextBox_Net_Applicant_US.Text = rowUser["Net_Applicant_US"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Counsellor"].ToString().Trim(), Drop_Counsellor);
                Common_SXD.SetSelectedIndex(rowUser["Writer"].ToString().Trim(), Drop_Writer);
                Common_SXD.SetSelectedIndex(rowUser["YearMonth_Start"].ToString().Trim(), Drop_YearMonth_Start);
                Common_SXD.SetSelectedIndex(rowUser["After_Visa_US"].ToString().Trim(), Drop_After_Visa_US);
                Common_SXD.SetSelectedIndex(rowUser["Net_Applicant_US"].ToString().Trim(), Drop_Net_Applicant_US);

                TextBox_Student_Name.Text = rowUser["Student_Name"].ToString().Trim();

                TextBox_Date_Completion_Offer.Text = rowUser["Date_Completion_Offer"].ToString().Trim();
                TextBox_Date_Completion_Offer.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer.Text);

                TextBox_Date_Completion_Offer_US.Text = rowUser["Date_Completion_Offer_US"].ToString().Trim();
                TextBox_Date_Completion_Offer_US.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer_US.Text);

                TextBox_Date_Application_Visa.Text = rowUser["Date_Application_Visa"].ToString().Trim();
                TextBox_Date_Application_Visa.Text = Common_SXD.TimeToYMD(TextBox_Date_Application_Visa.Text);

                TextBox_Date_Completion_Contract.Text = rowUser["Date_Completion_Contract"].ToString().Trim();
                TextBox_Date_Completion_Contract.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Contract.Text);


                TextBox_Termination_Refund.Text = rowUser["Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = rowUser["Date_Termination_Refund"].ToString().Trim();
                //				TextBox_Date_Termination_Refund.Text = TimeToYMD(TextBox_Date_Termination_Refund.Text);
                TextBox_Date_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Termination_Refund.Text);

                //	保留		TextBox_Date_Finished_Termination_Refund.Text = rowUser["Date_Comfirm_Termination_Refund"].ToString().Trim();
                //				TextBox_Date_Finished_Termination_Refund.Text = TimeToYMD(TextBox_Date_Finished_Termination_Refund.Text);



                //		TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                //		string sTemp.Format(TextBox_Date_Birth.Text, "{0:yyyy-MM-dd}");
                TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                TextBox_Date_Birth.Text = Common_SXD.TimeToYMD(TextBox_Date_Birth.Text);

                TextBox_Pinyi.Text = rowUser["Pinyi"].ToString().Trim();
                TextBox_No_Contract.Text = rowUser["No_Contract"].ToString().Trim();
                TextBox_No_Origin.Text = rowUser["No_Origin"].ToString().Trim();
                TextBox_Receipt.Text = rowUser["Receipt"].ToString().Trim();
                TextBox_Channel.Text = rowUser["Channel"].ToString().Trim();

                Common_SXD.SetSelectedIndex(rowUser["Student_Type"].ToString().Trim(), Drop_C_Student_Type);
                Common_SXD.SetSelectedIndex(rowUser["Destinations_OS"].ToString().Trim(), Drop_Destinations_OS);


                TextBox_Remitter.Text = rowUser["Remitter"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = rowUser["Date_Second_Receipt"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_Second_Receipt.Text);

                TextBox_Notes.Text = rowUser["Notes"].ToString().Trim();
                TextBox_Ref_Cash_No.Text = rowUser["Ref_Cash_No"].ToString().Trim();


                TextBox_Amount.Text = rowUser["Amount"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = rowUser["Date_First_Receipt"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_First_Receipt.Text);

                TextBox_First_Payment.Text = rowUser["First_Payment"].ToString().Trim();
                TextBox_Second_Payment.Text = rowUser["Second_Payment"].ToString().Trim();
                TextBox_Date_First_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_First_Payment"].ToString().Trim());
                TextBox_Date_Second_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_Second_Payment"].ToString().Trim());

                TextBox_Date_Return_OriginalContract.Text = Common_SXD.TimeToYMD(rowUser["Date_Return_OriginalContract"].ToString().Trim());
                
                Display_CheckBox_Deduct_FreeService();
                /*
                /////////////零中介退费后，显示是否扣奖选项
                Regex Deduct = new Regex("(Deduct)|(deduct)");
                if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
                {
                    if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                        (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                    {
                        CheckBox_Deduct_FreeService.Visible = true;
                        if (Deduct.IsMatch(TextBox_Notes.Text))
                        {
                            CheckBox_Deduct_FreeService.Checked = true;
                        }
                        else
                            CheckBox_Deduct_FreeService.Checked = false;
                    }
                    else
                        CheckBox_Deduct_FreeService.Visible = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;


                /////////////////////////////////////////////////////////////////////////////////////
                */
                if ((rowUser["Is_New"].ToString().Trim() == "True")||
                    (rowUser["Is_New"].ToString().Trim() == "1"))
                    CheckBox_Is_New.Checked = true;
                else
                    CheckBox_Is_New.Checked = false;

            }
            ///sqlCnn.Close();

            TextBox_Date_Return_OriginalContract.Enabled = false;
            /// TextBox_Date_First_Receipt.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_First_Receipt);
            /// 登记新合同后，3天内可以修改。
            Common_SXD.sElapsedSpan(TextBox_Date_First_Receipt, "Date_First_Receipt", 3);
            Common_SXD.sElapsedSpan(TextBox_Date_First_Receipt, "Date_First_Receipt", 3);


            Response.Write("<li>修改一期付款相关数据。</li>");

        }

        /// <summary>
        ///  初始化：只读合同数据
        /// </summary>
        private void Init_ReadOnly()
        {
            Is_SuperUser(true);
            /*
            SqlConnection sqlCnn = new SqlConnection(strCnn);
            // 根据传入的合同编号，生成查询 SQL 语句
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            SqlDataAdapter sqlDA = new SqlDataAdapter(sSql, sqlCnn);
            sqlDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            DataSet bsDataSet = new DataSet();
            sqlDA.Fill(bsDataSet, "Contract");
            */

            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";

            DataSet bsDataSet = Init_DataSet("Contract", sSql);
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行
                // 显示用户信息
                TextBox_Office.Text = rowUser["Office"].ToString().Trim();
                InitializeDrop_Counsellor(TextBox_Office.Text);
                InitializeDrop_Writer(TextBox_Office.Text);

                TextBox_Counsellor.Text = rowUser["Counsellor"].ToString().Trim();
                TextBox_Writer.Text = rowUser["Writer"].ToString().Trim();  
                TextBox_YearMonth_Start.Text = rowUser["YearMonth_Start"].ToString().Trim();
                TextBox_C_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();
                TextBox_After_Visa_US.Text = rowUser["After_Visa_US"].ToString().Trim();
                TextBox_Net_Applicant_US.Text = rowUser["Net_Applicant_US"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Counsellor"].ToString().Trim(), Drop_Counsellor);
                Common_SXD.SetSelectedIndex(rowUser["Writer"].ToString().Trim(), Drop_Writer);
                Common_SXD.SetSelectedIndex(rowUser["YearMonth_Start"].ToString().Trim(), Drop_YearMonth_Start);
                Common_SXD.SetSelectedIndex(rowUser["After_Visa_US"].ToString().Trim(), Drop_After_Visa_US);
                Common_SXD.SetSelectedIndex(rowUser["Net_Applicant_US"].ToString().Trim(), Drop_Net_Applicant_US);

                TextBox_Student_Name.Text = rowUser["Student_Name"].ToString().Trim();

                TextBox_Date_Completion_Offer.Text = rowUser["Date_Completion_Offer"].ToString().Trim();
                TextBox_Date_Completion_Offer.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer.Text);

                TextBox_Date_Completion_Offer_US.Text = rowUser["Date_Completion_Offer_US"].ToString().Trim();
                TextBox_Date_Completion_Offer_US.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer_US.Text);

                TextBox_Date_Application_Visa.Text = rowUser["Date_Application_Visa"].ToString().Trim();
                TextBox_Date_Application_Visa.Text = Common_SXD.TimeToYMD(TextBox_Date_Application_Visa.Text);

                TextBox_Date_Completion_Contract.Text = rowUser["Date_Completion_Contract"].ToString().Trim();
                TextBox_Date_Completion_Contract.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Contract.Text);


                TextBox_Termination_Refund.Text = rowUser["Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = rowUser["Date_Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Termination_Refund.Text);

                TextBox_Date_Finished_Termination_Refund.Text = rowUser["Date_Finished_Termination_Refund"].ToString().Trim();
                TextBox_Date_Finished_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Finished_Termination_Refund.Text);



                //		TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                //		string sTemp.Format(TextBox_Date_Birth.Text, "{0:yyyy-MM-dd}");
                TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                TextBox_Date_Birth.Text = Common_SXD.TimeToYMD(TextBox_Date_Birth.Text);

                TextBox_Pinyi.Text = rowUser["Pinyi"].ToString().Trim();
                TextBox_No_Contract.Text = rowUser["No_Contract"].ToString().Trim();
                TextBox_No_Origin.Text = rowUser["No_Origin"].ToString().Trim();
                TextBox_Receipt.Text = rowUser["Receipt"].ToString().Trim();
                TextBox_Channel.Text = rowUser["Channel"].ToString().Trim();

                Common_SXD.SetSelectedIndex(rowUser["Student_Type"].ToString().Trim(), Drop_C_Student_Type);
                Common_SXD.SetSelectedIndex(rowUser["Destinations_OS"].ToString().Trim(), Drop_Destinations_OS);


                TextBox_Remitter.Text = rowUser["Remitter"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = rowUser["Date_Second_Receipt"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_Second_Receipt.Text);

                TextBox_Date_Return_OriginalContract.Text = rowUser["Date_Return_OriginalContract"].ToString().Trim();
                TextBox_Date_Return_OriginalContract.Text = Common_SXD.TimeToYMD(TextBox_Date_Return_OriginalContract.Text);
                

                TextBox_Notes.Text = rowUser["Notes"].ToString().Trim();
                TextBox_Ref_Cash_No.Text = rowUser["Ref_Cash_No"].ToString().Trim();


                TextBox_Amount.Text = rowUser["Amount"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = rowUser["Date_First_Receipt"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_First_Receipt.Text);

                TextBox_First_Payment.Text = rowUser["First_Payment"].ToString().Trim();
                TextBox_Second_Payment.Text = rowUser["Second_Payment"].ToString().Trim();
                TextBox_Date_First_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_First_Payment"].ToString().Trim());
                TextBox_Date_Second_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_Second_Payment"].ToString().Trim());

                Display_CheckBox_Deduct_FreeService();
                /*
                /////////////零中介退费后，显示是否扣奖选项 Display_CheckBox_Deduct_FreeService
                Regex Deduct = new Regex("(Deduct)|(deduct)");
                if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
                {
                    if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                        (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                    {
                        CheckBox_Deduct_FreeService.Visible = true;
                        if (Deduct.IsMatch(TextBox_Notes.Text))
                        {
                            CheckBox_Deduct_FreeService.Checked = true;
                        }
                        else
                            CheckBox_Deduct_FreeService.Checked = false;
                    }
                    else
                        CheckBox_Deduct_FreeService.Visible = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;
               
                ///CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                ///TextBox_Add_Notes.Enabled = false;
                ///////////////////////////////////////////////
                */

                if ((rowUser["Is_New"].ToString().Trim() == "True") ||
                    (rowUser["Is_New"].ToString().Trim() == "1"))
                    CheckBox_Is_New.Checked = true;
                else
                    CheckBox_Is_New.Checked = false;

            }
            ///sqlCnn.Close();

        }


        /// <summary>
        /// 初始化，添加新的合同数据
        /// </summary>
        public void Init_NewOne()
        {
            bool bIs_Admin = Convert.ToBoolean(Session["Is_Admin"]);
            bool bIs_O_M = Convert.ToBoolean(Session["Is_O_M"]);
            bool bIs_Collector = Convert.ToBoolean(Session["Is_Collector"]);
            bool bIs_Accountant = Convert.ToBoolean(Session["Is_Accountant"]);
            bool bIs_Receptionist = Convert.ToBoolean(Session["Is_Receptionist"]);
            bool bIs_Writer = Convert.ToBoolean(Session["Is_Writer"]);
            bool bIs_Counsellor = Convert.ToBoolean(Session["Is_Counsellor"]);

            InitControls_NewOne_FirstPay();
            ///张玉稳可以修改一期款日期、新数据标志。
            ///
            if (Session["Email"].ToString().ToLower().Trim() == "yuwen_zhang")
            {
                TextBox_Date_First_Payment.Enabled = true;
                CheckBox_Is_New.Enabled = true;
            }

            TextBox_Office.Text = Session["Office"].ToString().Trim();
            InitializeDrop_Counsellor(TextBox_Office.Text);
            InitializeDrop_Writer(TextBox_Office.Text);

            TextBox_Date_First_Payment.Text = "1900-1-1";
            TextBox_Date_Second_Payment.Text = "1900-1-1";
            TextBox_Date_Completion_Offer.Text = "1900-1-1";
            TextBox_Date_Completion_Offer_US.Text = "1900-1-1";
            TextBox_Date_Application_Visa.Text = "1900-1-1";
            TextBox_Date_Completion_Contract.Text = "1900-1-1";
            TextBox_Date_Termination_Refund.Text = "1900-1-1";
            TextBox_Date_Birth.Text = "1900-1-1";

            DateTime time = DateTime.Now;
            TextBox_Date_First_Receipt.Text = Common_SXD.TimeToYMD(time.ToString().Trim());
            //TextBox_Date_Second_Receipt.Text = "1900-1-1";

            TextBox_Termination_Refund.Text = "0";
            //			TextBox_First_Payment.Text = "0";
            TextBox_Second_Payment.Text = "0";

            if (!bIs_Counsellor)
                TextBox_Counsellor.Text = "?";
            else
            {
                TextBox_Counsellor.Text = Session["C_N_Employee"].ToString().Trim();
            }
            TextBox_Writer.Text = "?";
            TextBox_After_Visa_US.Text = "?";
            TextBox_Net_Applicant_US.Text = "?";


            Common_SXD.SetSelectedIndex("?", Drop_Counsellor);
            Common_SXD.SetSelectedIndex("?", Drop_Writer);
            //			TextBox_Student_Name.Text = "学生";
            //			TextBox_Pinyi.Text = "XUE Sheng";

            Common_SXD.SetSelectedIndex("?", Drop_After_Visa_US);
            Common_SXD.SetSelectedIndex("?", Drop_Net_Applicant_US);

            TextBox_Date_Return_OriginalContract.Enabled = false;

            Response.Write("<li>添加新合同! </li>");

            Display_CheckBox_Deduct_FreeService();
            /*
            /////////////零中介退费后，显示是否扣奖选项
            Regex Deduct = new Regex("(Deduct)|(deduct)");
            if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
            {
                if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                    (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                {
                    CheckBox_Deduct_FreeService.Visible = true;
                    if (Deduct.IsMatch(TextBox_Notes.Text))
                    {
                        CheckBox_Deduct_FreeService.Checked = true;
                    }
                    else
                        CheckBox_Deduct_FreeService.Checked = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;
            }
            else
                CheckBox_Deduct_FreeService.Visible = false;

            /////////////////////////////////////////////////////////////////////////////////////
            */

            //Label_Msg.Text = sSeries_No;
            //Session.Clear();   
            //Session.Abandon();   
            //			Response.Write("<script>alert('新的记录已经生成！进入修改状态！');location.href='./ContractEdit.aspx?Series_No=" + sSeries_No + "';</script>");   
            //			Response.End();   

        }

        /// <summary>
        /// 零中介退费后，显示是否扣奖选项
        /// </summary>      
        private void Display_CheckBox_Deduct_FreeService()
        {
            /////////////零中介退费后，显示是否扣奖选项 
            Regex Deduct = new Regex("(Deduct)|(deduct)");
            if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
            {
                if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                    (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                {
                    CheckBox_Deduct_FreeService.Visible = true;
                    if (Deduct.IsMatch(TextBox_Notes.Text))
                    {
                        CheckBox_Deduct_FreeService.Checked = true;
                    }
                    else
                        CheckBox_Deduct_FreeService.Checked = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;
            }
            else
                CheckBox_Deduct_FreeService.Visible = false;
            /*
            CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
            TextBox_Add_Notes.Enabled = false;
            */
            ///////////////////////////////////////////////



        }
        /// <summary>
        /// 判断当前用户是否特殊权限用户，在 Init_ReadOnly 函数中，修改特殊用户的编辑权限。
        /// </summary>
       private bool Is_SuperUser(bool Is_In_Init_ReadOnly)
       {
            string Name_Email = Session["Email"].ToString().Trim().ToLower();
            if (Name_Email == "jianwei_rong")
            {
               
                if (Is_In_Init_ReadOnly)///仅在 Init_ReadOnly 函数内生效的代码
                {
                    CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                    CheckBox_Deduct_FreeService.Visible = true;
                    TextBox_Add_Notes.Enabled = false;
                    TextBox_Writer.Enabled = false;
                    TextBox_Counsellor.Enabled = false;
                    TextBox_YearMonth_Start.Enabled = false; 
                    TextBox_C_Student_Type.Enabled = false;
                    TextBox_Net_Applicant_US.Enabled = false;
                    TextBox_After_Visa_US.Enabled = false;

                    Response.Write("<li>学生合同详细资料。jianwei rong </li>");
                }
                return true;
            }
            else if (Name_Email == "joanna_bai")
                        {
                            if (Is_In_Init_ReadOnly)///仅在 Init_ReadOnly 函数内生效的代码
                            {
                                CheckBox_Is_New.Enabled = false;

                                TextBox_Counsellor.Enabled = false;
                                Drop_Counsellor.Enabled = false;
                                TextBox_Writer.Enabled = false;  
                                TextBox_YearMonth_Start.Enabled = false; 
                                TextBox_C_Student_Type.Enabled = false;
                                TextBox_After_Visa_US.Enabled = false;
                                TextBox_Net_Applicant_US.Enabled = false;
                                Drop_Writer.Enabled = false; 
                                Drop_YearMonth_Start.Enabled = false;
                                Drop_After_Visa_US.Enabled = false;
                                Drop_Net_Applicant_US.Enabled = false;
                                TextBox_Student_Name.Enabled = false;
                                TextBox_Pinyi.Enabled = false;
                                TextBox_Date_Birth.Enabled = false;
                                TextBox_Date_First_Receipt.Enabled = false;
                                TextBox_No_Contract.Enabled = false;
                                TextBox_Amount.Enabled = false;
                                Drop_C_Student_Type.Enabled = false;
                                Drop_Destinations_OS.Enabled = false;
                                TextBox_First_Payment.Enabled = false;
                                TextBox_Date_First_Payment.Enabled = false;
                                TextBox_Date_Second_Receipt.Enabled = false;
                                TextBox_Second_Payment.Enabled = false;
                                TextBox_Date_Second_Payment.Enabled = false;
                                TextBox_Date_Completion_Offer.Enabled = false;
                                TextBox_Date_Completion_Offer_US.Enabled = false;
                                TextBox_Date_Application_Visa.Enabled = false;
                                TextBox_Date_Completion_Contract.Enabled = false;
                                //关闭 Notes 和 Notes 添加
                                TextBox_Notes.Enabled = false;
                                TextBox_Add_Notes.Enabled = true;
                                CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                                CheckBox_Deduct_FreeService.Visible = true;

                                TextBox_Termination_Refund.Enabled = false;
                                TextBox_Date_Termination_Refund.Enabled = false;
                                TextBox_Date_Finished_Termination_Refund.Enabled = false;
                                TextBox_Remitter.Enabled = false;
                                TextBox_Date_Second_Receipt.Enabled = false;

                                TextBox_Date_Return_OriginalContract.Enabled = false;

                                //查看长字符串			TextBox_Ref_Cash_No.Enabled = false;
                                TextBox_Office.Enabled = false;

                                // Bt_OK.Enabled = false;
                                // Bt_Reset.Disabled  = true;

                                Response.Write("<li>学生合同详细资料。joanna bai </li>");

                            }
                            return true;
                        }
                        else if (Name_Email == "xiaorong_liu")
                        {
                            if (Is_In_Init_ReadOnly)///仅在 Init_ReadOnly 函数内生效的代码
                            {
                                CheckBox_Is_New.Enabled = false;

                                TextBox_Counsellor.Enabled = false;
                                Drop_Counsellor.Enabled = false;
                                TextBox_Writer.Enabled = false;  
                                TextBox_YearMonth_Start.Enabled = false; 
                                TextBox_C_Student_Type.Enabled = false;
                                TextBox_After_Visa_US.Enabled = false;
                                TextBox_Net_Applicant_US.Enabled = false;
                                Drop_Writer.Enabled = false; 
                                Drop_YearMonth_Start.Enabled = false;
                                Drop_After_Visa_US.Enabled = false;
                                Drop_Net_Applicant_US.Enabled = false;
                                TextBox_Student_Name.Enabled = false;
                                TextBox_Pinyi.Enabled = false;
                                TextBox_Date_Birth.Enabled = false;
                                TextBox_Date_First_Receipt.Enabled = false;
                                TextBox_Date_Second_Receipt.Enabled = false;
                                TextBox_No_Contract.Enabled = false;
                                TextBox_Amount.Enabled = false;
                                Drop_C_Student_Type.Enabled = false;
                                Drop_Destinations_OS.Enabled = false;
                                TextBox_First_Payment.Enabled = false;
                                TextBox_Date_First_Payment.Enabled = false;
                                TextBox_Second_Payment.Enabled = false;
                                TextBox_Date_Second_Payment.Enabled = false;
                                TextBox_Date_Completion_Offer.Enabled = false;
                                TextBox_Date_Completion_Offer_US.Enabled = false;
                                TextBox_Date_Application_Visa.Enabled = false;
                                TextBox_Date_Completion_Contract.Enabled = false;
                                //关闭 Notes 和 Notes 添加
                                TextBox_Notes.Enabled = true;
                                TextBox_Add_Notes.Enabled = false;
                                CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                                CheckBox_Deduct_FreeService.Visible = true;

                                TextBox_Termination_Refund.Enabled = false;
                                TextBox_Date_Termination_Refund.Enabled = false;
                                TextBox_Date_Finished_Termination_Refund.Enabled = false;
                                TextBox_Remitter.Enabled = false;
                                TextBox_Date_Return_OriginalContract.Enabled = false;
                                TextBox_Date_Second_Receipt.Enabled = false;

                                TextBox_Date_Return_OriginalContract.Enabled = false;
                    
                                //查看长字符串			TextBox_Ref_Cash_No.Enabled = false;
                                TextBox_Office.Enabled = false;

                                // Bt_OK.Enabled = false;
                                // Bt_Reset.Disabled  = true;

                                Response.Write("<li>学生合同详细资料。xiaorong liu </li>");

                            }
                            return true;
                        }
                        else if (Name_Email == "yuwen_zhang")
                        {
                            if (Is_In_Init_ReadOnly)///仅在 Init_ReadOnly 函数内生效的代码
                            {
                                CheckBox_Is_New.Enabled = false;

                                TextBox_Counsellor.Enabled = false;
                                Drop_Counsellor.Enabled = false;
                                TextBox_Writer.Enabled = false;  
                                TextBox_YearMonth_Start.Enabled = false; 
                                TextBox_C_Student_Type.Enabled = false;
                                TextBox_After_Visa_US.Enabled = false;
                                TextBox_Net_Applicant_US.Enabled = false;
                                Drop_Writer.Enabled = false; 
                                Drop_YearMonth_Start.Enabled = false;
                                Drop_After_Visa_US.Enabled = false;
                                Drop_Net_Applicant_US.Enabled = false;
                                TextBox_Student_Name.Enabled = false;
                                TextBox_Pinyi.Enabled = false;
                                TextBox_Date_Birth.Enabled = false;
                                TextBox_Date_First_Receipt.Enabled = false;
                                TextBox_Date_Second_Receipt.Enabled = false;
                                TextBox_No_Contract.Enabled = false;
                                TextBox_Amount.Enabled = false;
                                Drop_C_Student_Type.Enabled = false;
                                Drop_Destinations_OS.Enabled = false;
                                TextBox_First_Payment.Enabled = false;
                                TextBox_Date_First_Payment.Enabled = false;
                                TextBox_Second_Payment.Enabled = false;
                                TextBox_Date_Second_Payment.Enabled = false;
                                TextBox_Date_Completion_Offer.Enabled = false;
                                TextBox_Date_Completion_Offer_US.Enabled = false;
                                TextBox_Date_Application_Visa.Enabled = false;
                                TextBox_Date_Completion_Contract.Enabled = false;
                                //关闭 Notes 和 Notes 添加
                                TextBox_Notes.Enabled = true;
                                TextBox_Add_Notes.Enabled = false;
                                CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                                CheckBox_Deduct_FreeService.Visible = true;

                                TextBox_Termination_Refund.Enabled = false;
                                TextBox_Date_Termination_Refund.Enabled = false;
                                TextBox_Date_Finished_Termination_Refund.Enabled = false;
                                TextBox_Remitter.Enabled = false;

                                TextBox_Date_Return_OriginalContract.Enabled = false;
                    
                                TextBox_Date_Second_Receipt.Enabled = false;
                                //查看长字符串			TextBox_Ref_Cash_No.Enabled = false;
                                TextBox_Office.Enabled = false;

                                // Bt_OK.Enabled = false;
                                // Bt_Reset.Disabled  = true;

                                Response.Write("<li>学生合同详细资料。yuwen zhang </li>");

                            }
                            return true;
                        }


            if (Is_In_Init_ReadOnly)///仅在 Init_ReadOnly 函数内生效的代码
            {
                CheckBox_Is_New.Enabled = false;

                TextBox_Counsellor.Enabled = false;
                Drop_Counsellor.Enabled = false;
                TextBox_Writer.Enabled = false;  
                TextBox_YearMonth_Start.Enabled = false; 
                TextBox_C_Student_Type.Enabled = false;
                TextBox_After_Visa_US.Enabled = false;
                TextBox_Net_Applicant_US.Enabled = false;
                Drop_Writer.Enabled = false; 
                Drop_YearMonth_Start.Enabled = false;
                Drop_After_Visa_US.Enabled = false;
                Drop_Net_Applicant_US.Enabled = false;
                TextBox_Student_Name.Enabled = false;
                TextBox_Pinyi.Enabled = false;
                TextBox_Date_Birth.Enabled = false;
                TextBox_Date_First_Receipt.Enabled = false;
                TextBox_Date_Second_Receipt.Enabled = false;
                TextBox_No_Contract.Enabled = false;
                TextBox_Amount.Enabled = false;
                Drop_C_Student_Type.Enabled = false;
                Drop_Destinations_OS.Enabled = false;
                TextBox_First_Payment.Enabled = false;
                TextBox_Date_First_Payment.Enabled = false;
                TextBox_Second_Payment.Enabled = false;
                TextBox_Date_Second_Payment.Enabled = false;
                TextBox_Date_Completion_Offer.Enabled = false;
                TextBox_Date_Completion_Offer_US.Enabled = false;
                TextBox_Date_Application_Visa.Enabled = false;
                TextBox_Date_Completion_Contract.Enabled = false;
                //关闭 Notes 和 Notes 添加
                TextBox_Notes.Enabled = false;
                TextBox_Add_Notes.Enabled = false;

                CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项

                TextBox_Termination_Refund.Enabled = false;
                TextBox_Date_Termination_Refund.Enabled = false;
                TextBox_Date_Finished_Termination_Refund.Enabled = false;
                TextBox_Remitter.Enabled = false;
                TextBox_Date_Second_Receipt.Enabled = false;

                TextBox_Date_Return_OriginalContract.Enabled = false;
                
                //查看长字符串			TextBox_Ref_Cash_No.Enabled = false;
                TextBox_Office.Enabled = false;

                Bt_OK.Enabled = false;
                //			Bt_Reset.Disabled  = true;

                Response.Write("<li>学生合同详细资料，不能修改。</li>");

            }          
            return false;
        }

        /// <summary>
        /// 如果myTextBox_Date日期为空，允许修改"日期字段"
        /// 如果myTextBox_Date日期无效，也允许修改"日期字段"
        /// </summary>
        /// <param name="myTextBox_Date"></param>
        /// <returns></returns>
        private bool Is_Allowed_OnceEdit_Date(TextBox myTextBox_Date )
        {
           if (myTextBox_Date.Text.ToString().Trim() != "")
           {
               if (Convert.ToDateTime(myTextBox_Date.Text) < Convert.ToDateTime("1930-1-1"))
                   return true;
               else
                   return false;
           }
           else
               return true;       
        }

        /// <summary>
        /// 判断数据错误（金额、一期款、二期款）
        /// </summary>
        public bool Is_WrongPayment()
        {
            //不合理数据
            double Amount = Convert.ToDouble(TextBox_Amount.Text);
            double First_Payment = Convert.ToDouble(TextBox_First_Payment.Text);
            double Second_Payment = Convert.ToDouble(TextBox_Second_Payment.Text);
            double Termination_Refund = Convert.ToDouble(TextBox_Termination_Refund.Text);

            if (Amount < (First_Payment + Second_Payment))
            {
                Response.Write("<li>合同金额与付款数据有错， 不能保存！</li>");
                return true;
            }
            
            if (Termination_Refund == 0 && TextBox_Date_Termination_Refund.Text.ToString().Trim() != ""
                && TextBox_Date_Termination_Refund.Text.ToString().Trim() != "1900-1-1")
            {
                Response.Write("<li>退款金额为0，不能填写退款日期！</li>");
                return true;
            }



            /// 注释中不能出现 "SH" ,不能出现“SHANGHAI”
            string Notes = Convert.ToString(TextBox_Notes.Text);
            string Add_Notes = Convert.ToString(TextBox_Add_Notes.Text);
            //// Regex SH_SHANGHAI = new Regex("(Shanghai)|(SH[^\\s+])", RegexOptions.IgnoreCase);
            Regex SH_SHANGHAI = new Regex("(Shanghai)", RegexOptions.IgnoreCase);
            if (SH_SHANGHAI.IsMatch(Notes) || SH_SHANGHAI.IsMatch(Add_Notes))
            {
                Response.Write("<li>注释中不能出现 “Shanghai”！不能保存！</li>");
                return true;
            }

            return false;
        }


        /// <summary>
        /// 判定日期字符串是否在本月的计奖日期内
        /// </summary>
        public bool IsInMonthBonus(string sDate)
        {
            //////当前时间-> 年-月
            ///
            System.DateTime bonusDateTime = System.DateTime.Now;

            string sTime = Convert.ToString(bonusDateTime.Year) + '-' + Convert.ToString(bonusDateTime.Month);
            ///
            /// 26日起，算下一个计奖月
            /// 
            if (bonusDateTime.Day > 25)
            {
                if(bonusDateTime.Month < 12)
                    sTime = Convert.ToString(bonusDateTime.Year) + '-' + Convert.ToString(bonusDateTime.Month + 1); 
                else
                    sTime = Convert.ToString(bonusDateTime.Year + 1 ) + "-1";
            }

            Common_SXD.Set_BonusDate(sTime, true); ////判定准许填写退款的范围

            Regex IsYearMonthDay = new Regex("[0-9]{4}(-){1}[0-9]{1,2}(-){1}[0-9]{1,2}");
            if (IsYearMonthDay.IsMatch(sDate))
            {
                if (Convert.ToDateTime(sDate) >= Convert.ToDateTime(Common_SXD.strStartDate) &&
                    Convert.ToDateTime(sDate) <= Convert.ToDateTime(Common_SXD.strEndingDate))
                    return true;
                else
                {
                    Response.Write("<li>申请退款日期不在本月！不能修改：申请退款日期、申请退款金额！</li>");
                    return false;
                }
            }
            else
            {
                Response.Write("<li>申请退款日期不在本月！不能修改：申请退款日期、申请退款金额！</li>");
                return false;
            }

        }


        /// <summary>
        /// 确认退款成功
        /// </summary>
        public void Check_FinishedTerminationRefund()
        {
            //不合理数据
            if (Is_WrongPayment())
                return;
            /*
            SqlConnection sqlCnn = new SqlConnection();
            sqlCnn.ConnectionString = strCnn;
            sqlCnn.Open(); // 建立连接
            SqlCommand sqlCmd = sqlCnn.CreateCommand(); // 创建 command 对象
            sqlCmd.CommandType = CommandType.Text; // 类型为 SQL 语句
            */
            //合同信息写入数据库
            string sSql = "Update Contract Set";
            //			sSql += " Counsellor = '" + TextBox_Counsellor.Text.Trim()  + "',";
            //			sSql += " Writer = '" + TextBox_Writer.Text.Trim()  + "', ";
            //			sSql += " Student_Name = '" + TextBox_Student_Name.Text.Trim()  + "', ";
            //			sSql += " Date_Birth = '" + TextBox_Date_Birth.Text.Trim()  + "', ";
            //			sSql += " No_Contract = '" + TextBox_No_Contract.Text.Trim()  + "', ";
            //			sSql += " No_Origin = '" + TextBox_No_Origin.Text.Trim()  + "', ";

            //			sSql += " Student_Type = '" + Drop_C_Student_Type.SelectedItem.Text.Trim()  + "', ";
            //		sSql += " Student_Type = '" + TextBox_Student_Type.Text.Trim()  + "', ";

            // sSql += " Remitter = '" + TextBox_Remitter.Text.Trim()  + "', ";
            // sSql += " Date_Second_Receipt = '" + TextBox_Date_Second_Receipt.Text.Trim()  + "', ";

            //			sSql += " Notes = '" + TextBox_Notes.Text.Trim()  + "', ";
            string sNotes = TextBox_Notes.Text.Trim();
            if (TextBox_Add_Notes.Text.Trim().Length > 0)
            {
                sNotes += " " + TextBox_Add_Notes.Text.Trim();
                sSql += " Notes = '" + sNotes + "', ";
            }
            ///////////////////////////////

            //sSql += " Amount = '" + TextBox_Amount.Text.Trim()  + "', ";
            sSql += " Pinyi = '" + TextBox_Pinyi.Text.Trim() + "', ";
            //sSql += " First_Payment = '" + TextBox_First_Payment.Text.Trim()  + "', ";
            //sSql += " Second_Payment = '" + TextBox_Second_Payment.Text.Trim()  + "', ";
            //sSql += " Date_First_Payment = '" + TextBox_Date_First_Payment.Text.Trim()  + "', ";
            sSql += " Date_Finished_Termination_Refund = '" + TextBox_Date_Finished_Termination_Refund.Text.Trim() + "' ";
            /*		
                        string temp;
                        if(CheckBox_Is_New.Checked == true)
                            temp = "1";
                        else
                            temp = "0";
                        sSql += " Is_New = '" + temp  + "' ";
            */
            sSql += " where Series_No = " + "'" + Label_Msg.Text.Trim() + "'";
            
            Common_SXD.MSSql_ExecuteNonQuery(sSql, "" , "<li>更新数据出错：", Response);
        }


        /// <summary>
        /// 确认第一次付款相关的数据（此时还是新数据，确认后不是新数据）
        /// </summary>
        public void Check_FirstPayment()
        {
            //不合理数据
            if (Is_WrongPayment())
                return;
            /*
            SqlConnection sqlCnn = new SqlConnection();
            sqlCnn.ConnectionString = strCnn;
            sqlCnn.Open(); // 建立连接
            SqlCommand sqlCmd = sqlCnn.CreateCommand(); // 创建 command 对象
            sqlCmd.CommandType = CommandType.Text; // 类型为 SQL 语句
            */

            //合同信息写入数据库
            string sSql = "Update Contract Set";
            //			sSql += " Counsellor = '" + TextBox_Counsellor.Text.Trim()  + "',";
            //			sSql += " Writer = '" + TextBox_Writer.Text.Trim()  + "', ";
            //			sSql += " Student_Name = '" + TextBox_Student_Name.Text.Trim()  + "', ";
            //			sSql += " Date_Birth = '" + TextBox_Date_Birth.Text.Trim()  + "', ";
            //			sSql += " No_Contract = '" + TextBox_No_Contract.Text.Trim()  + "', ";
            //			sSql += " No_Origin = '" + TextBox_No_Origin.Text.Trim()  + "', ";

            //			sSql += " Student_Type = '" + Drop_C_Student_Type.SelectedItem.Text.Trim()  + "', ";
            //		sSql += " Student_Type = '" + TextBox_Student_Type.Text.Trim()  + "', ";

            sSql += " Remitter = '" + TextBox_Remitter.Text.Trim() + "', ";
            ///sSql += " Date_Second_Receipt = '" + TextBox_Date_Second_Receipt.Text.Trim() + "', ";
            sSql = sSql_Add_DateTime(TextBox_Date_Second_Receipt, "Date_Second_Receipt", sSql);
            //			sSql += " Notes = '" + TextBox_Notes.Text.Trim()  + "', ";
            string sNotes = TextBox_Notes.Text.Trim();
            if (TextBox_Add_Notes.Text.Trim().Length > 0)
            {
                sNotes += " " + TextBox_Add_Notes.Text.Trim();
                sSql += " Notes = '" + sNotes + "', ";
            }
            ///////////////////////////////

            sSql += " Amount = '" + TextBox_Amount.Text.Trim() + "', ";
            sSql += " Pinyi = '" + TextBox_Pinyi.Text.Trim() + "', ";
            sSql += " First_Payment = '" + TextBox_First_Payment.Text.Trim() + "', ";
            sSql += " Second_Payment = '" + TextBox_Second_Payment.Text.Trim() + "', ";
            sSql += " Date_First_Payment = '" + TextBox_Date_First_Payment.Text.Trim() + "', ";
            sSql += " Date_Second_Payment = '" + TextBox_Date_Second_Payment.Text.Trim() + "', ";

            string temp;
            if (CheckBox_Is_New.Checked == true)
                temp = "1";
            else
                temp = "0";
            sSql += " Is_New = '" + temp + "' ";

            sSql += " where Series_No = " + "'" + Label_Msg.Text.Trim() + "'";
            
            
#if MSSql
            Common_SXD.MSSql_ExecuteNonQuery(sSql, "", "更新数据出错：", Response);
#elif MySql
            Common_SXD.MySql_ExecuteNonQuery(sSql, "", "更新数据出错：", Response);
#endif
        }

        ///////////////////////////
        private string UpdatingNotes(string mySql,/* string myNotes,*/ HttpResponse myResponse)
        {

            string sNotes = TextBox_Notes.Text.Trim();
            sNotes = sNotes.Trim();
            Regex Deduct = new Regex("(Deduct)|(deduct)");
            Regex CommaDeduct = new Regex("([,]*[ ]*Deduct)|([，]*[ ]*Deduct)");

            ////设定填写退款的判断范围
            Common_SXD.Set_BonusDate(Common_SXD.TimeToYM(TextBox_Date_Termination_Refund.Text.Trim()), true);

            if (TextBox_Add_Notes.Text.Trim().Length > 0)///判断Add_Notes
            {
                string temp0 = TextBox_Add_Notes.Text.Trim();

                // 注释中有内容，根据添加字符串的首字符判断
                if (TextBox_Notes.Text.Trim().Length > 0)
                {
                    //	string temp0 =	TextBox_Add_Notes.Text.Trim();
                    char temp1 = temp0[0];
                    if (temp1 == ',') // 首字符为逗号，直接添加；
                        sNotes += temp0;
                    else if (temp1 == '，')
                        sNotes += temp0;
                    else // 首字符不是逗号， + “ “ + TextBox_Add_Notes.Text.Trim();
                        sNotes += " " + temp0;
                }
                else // 注释中无内容，直接添加
                {
                    sNotes += temp0;
                }

                /////////添加零中介退款扣奖信息
                ///////允许显示零中介扣款信息
                if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
                {
                    if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                        (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                        if (CheckBox_Deduct_FreeService.Checked)
                        {
                            if (!Deduct.IsMatch(TextBox_Notes.Text))
                            {
                                mySql += " Notes = '" + sNotes + ", Deduct ', ";
                                //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                            }
                            else
                            {
                                mySql += " Notes = '" + sNotes + "', ";
                                //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                            }
                        }
                        else
                        {/////清除扣款信息(当前日期在申请退费日期所在月的25日之前，有效)
                            if (DateTime.Now <= Convert.ToDateTime(Common_SXD.strEndingDate))
                            {
                                if (Deduct.IsMatch(TextBox_Notes.Text))
                                {
                                    string temp = CommaDeduct.Replace(sNotes, " ");
                                    mySql += " Notes = '" + temp + "', ";
                                    //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                                }
                                else
                                {
                                    mySql += " Notes = '" + sNotes + "', ";
                                    //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                                }
                            }
                            else
                                Response.Write("<li>不能清除扣款信息！</li>");

                        }
                    /////////////
                    ///添加注释
                    /////////////
                    else
                    {
                        mySql += " Notes = '" + sNotes + "', ";
                        //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                    }

                }
                /////////////
                ///添加注释
                /////////////
                else
                {
                    mySql += " Notes = '" + sNotes + "', ";
                    //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                }

            }
            else
            {//// 没有 add_notes 信息
                /////////添加零中介退款扣奖信息
                ///////允许显示零中介扣款信息
                ///
                if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
                {
                    if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                        (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                        if (CheckBox_Deduct_FreeService.Checked)
                        {
                            if (!Deduct.IsMatch(TextBox_Notes.Text))
                            {
                                mySql += " Notes = '" + sNotes + ", Deduct ', ";
                                //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                            }

                        }
                        else
                        {/////清除扣款信息(当前日期在申请退费日期所在月的25日之前，有效)
                            if (DateTime.Now <= Convert.ToDateTime(Common_SXD.strEndingDate))
                            {

                                if (Deduct.IsMatch(TextBox_Notes.Text))
                                {
                                    string temp = CommaDeduct.Replace(sNotes, " ");
                                    mySql += " Notes = '" + temp + "', ";
                                    //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                                }
                            }
                            else
                                Response.Write("<li>不能清除扣款信息！");

                        }
                }
                /////////////
                ///添加注释
                /////////////
                else if (sNotes.Length > 0)
                {
                    mySql += " Notes = '" + sNotes + "', ";
                    //Response.Write("<li>已经添加了注释信息，需要关闭窗口，刷新，才能看到添加的结果！</li>");
                }
 //               else
 //                   mySql = "";

            }

            return mySql;
        }

        /////////////////////////////
        /// <summary>
        /// 更新合同数据库的记录（不是新数据）。
        /// </summary>
        /// <remarks>
        /// 只有修改数据的控件有效（enable）时，该数据才能被更新。
        /// </remarks>
        public void Update_Contract()
        {
            //不合理收费数据与合同金额数据
            if (Is_WrongPayment())
                return;
            
            //合同信息写入数据库
            string sSql = "Update Contract Set";

            ///if( TextBox_Counsellor.Enabled)
            ///    sSql += " Counsellor = '" + TextBox_Counsellor.Text.Trim() + "',";
            sSql = sSql_Add_DropDownList(Drop_Counsellor, TextBox_Counsellor, "Counsellor", sSql);

            if( TextBox_Student_Name.Enabled)
                sSql += " Student_Name = '" + TextBox_Student_Name.Text.Trim() + "', ";
            /*
            if (TextBox_Date_Birth.Enabled)
                sSql += " Date_Birth = '" + TextBox_Date_Birth.Text.Trim() + "', ";
            */
            sSql = sSql_Add_DateTime(TextBox_Date_Birth, "Date_Birth", sSql);
            sSql = sSql_Add_DateTime(TextBox_Date_Completion_Offer, "Date_Completion_Offer", sSql);
            sSql = sSql_Add_DateTime(TextBox_Date_Completion_Offer_US, "Date_Completion_Offer_US", sSql);
            sSql = sSql_Add_DateTime(TextBox_Date_Application_Visa, "Date_Application_Visa", sSql);
            sSql = sSql_Add_DateTime(TextBox_Date_Completion_Contract, "Date_Completion_Contract", sSql);
            /*
            if (TextBox_Date_Completion_Offer.Enabled)
                sSql += " Date_Completion_Offer = '" + TextBox_Date_Completion_Offer.Text.Trim() + "', ";

            if (TextBox_Date_Completion_Offer_US.Enabled)
                sSql += " Date_Completion_Offer_US = '" + TextBox_Date_Completion_Offer_US.Text.Trim() + "', ";

            if (TextBox_Date_Application_Visa.Enabled)
                sSql += " Date_Application_Visa = '" + TextBox_Date_Application_Visa.Text.Trim() + "', ";

            if (TextBox_Date_Completion_Contract.Enabled)
                sSql += " Date_Completion_Contract = '" + TextBox_Date_Completion_Contract.Text.Trim() + "',";
            */

            if( TextBox_Pinyi.Enabled)
                sSql += " Pinyi = '" + TextBox_Pinyi.Text.Trim() + "', ";
            
            if(Get_Function(Session["Flag"].ToString().Trim()) == Func.EditContractFirstPay)
            {
                // 判断当前操作的“上月锁定状态”
                if (!Common_SXD.IsLock_LockDay_LastMonth(TextBox_Date_First_Receipt, Response))
                    sSql = sSql_Add_DateTime(TextBox_Date_First_Receipt, "Date_First_Receipt", sSql);
            }
            else
                sSql = sSql_Add_DateTime(TextBox_Date_First_Receipt, "Date_First_Receipt", sSql);

            if (TextBox_No_Contract.Enabled)
                sSql += " No_Contract = '" + TextBox_No_Contract.Text.Trim() + "', ";

            if (TextBox_Amount.Enabled)
                sSql += " Amount = '" + TextBox_Amount.Text.Trim() + "', ";

            if (Drop_YearMonth_Start.Enabled)/// 下拉选项有效，用TextBox更新数据库字段
                sSql += " YearMonth_Start = '" + TextBox_YearMonth_Start.Text.Trim() + "', ";

            if (Drop_C_Student_Type.Enabled)/// 下拉选项有效，用TextBox更新数据库字段
                ///sSql += " Student_Type = '" + Drop_C_Student_Type.SelectedItem.Text.Trim() + "', ";
                sSql += " Student_Type = '" + TextBox_C_Student_Type.Text.Trim() + "', ";

            if (Drop_Destinations_OS.Enabled)
                sSql += " Destinations_OS = '" + Drop_Destinations_OS.SelectedItem.Text.Trim() + "', ";

            if (TextBox_Notes.Enabled)
                sSql += " Notes = '" + TextBox_Notes.Text.Trim() + "', ";
            else
                sSql = UpdatingNotes(sSql, Response);

            if (TextBox_First_Payment.Enabled)
                sSql += " First_Payment = '" + TextBox_First_Payment.Text.Trim() + "', ";
            /*
            if (TextBox_Date_First_Payment.Enabled)
                sSql += " Date_First_Payment = '" + TextBox_Date_First_Payment.Text.Trim() + "', ";
            if (TextBox_Date_Return_OriginalContract.Enabled)
                sSql += " Date_Return_OriginalContract = '" + TextBox_Date_Return_OriginalContract.Text.Trim() + "', ";
            */
            sSql = sSql_Add_DateTime(TextBox_Date_First_Payment, "Date_First_Payment", sSql);
            sSql = sSql_Add_DateTime(TextBox_Date_Return_OriginalContract, "Date_Return_OriginalContract", sSql);
            
            if (TextBox_Second_Payment.Enabled)
                sSql += " Second_Payment = '" + TextBox_Second_Payment.Text.Trim() + "', ";
            /*
            if (TextBox_Date_Second_Payment.Enabled)
                sSql += " Date_Second_Payment = '" + TextBox_Date_Second_Payment.Text.Trim() + "', ";
            */
            sSql = sSql_Add_DateTime(TextBox_Date_Second_Payment, "Date_Second_Payment", sSql);
            /*
            string temp;
            if (CheckBox_Is_New.Enabled)
            {
                if (CheckBox_Is_New.Checked == true)
                    temp = "1";
                else
                    temp = "0";
                sSql += " Is_New = '" + temp + "', ";
            }*/
            sSql = sSql_Add_Checkd(CheckBox_Is_New, "Is_New", sSql);

            if (!Is_SuperUser(false))//Session["Email"].ToString().Trim() != "jianwei_rong")
            {
                if (TextBox_Date_Termination_Refund.Enabled && TextBox_Date_Termination_Refund.Text.Length > 0)
                {
                    if (IsInMonthBonus(TextBox_Date_Termination_Refund.Text.Trim()))
                    {
                        if (Convert.ToDouble(TextBox_Termination_Refund.Text.Trim()) >= 0.0)
                        {//申请退款日期在本月,同时, 退款金额大于等于0，才能修改
                            ///sSql += " Date_Termination_Refund = '" + TextBox_Date_Termination_Refund.Text.Trim() + "', ";
                            sSql = sSql_Add_DateTime(TextBox_Date_Termination_Refund, "Date_Termination_Refund", sSql);
                            sSql += " Termination_Refund = '" + TextBox_Termination_Refund.Text.Trim() + "', ";
                        }
                        else
                        {
                            Response.Write("<li>退款金额小于零，不能更新！</li>");
                        }
                    }
                }
            }
            else
                if (TextBox_Date_Termination_Refund.Enabled )
                {
                    ///sSql += " Date_Termination_Refund = '" + TextBox_Date_Termination_Refund.Text.Trim() + "', ";
                    sSql = sSql_Add_DateTime(TextBox_Date_Termination_Refund, "Date_Termination_Refund", sSql);
                    sSql += " Termination_Refund = '" + TextBox_Termination_Refund.Text.Trim() + "', ";
                       
                }
            

//            if( TextBox_Date_Finished_Termination_Refund.Enabled)
//                sSql += " Date_Permitting_Termination_Refund = '" + TextBox_Date_Finished_Termination_Refund.Text.Trim() + "', ";
            /*
            if( TextBox_Date_Finished_Termination_Refund.Enabled)
                sSql += " Date_Finished_Termination_Refund = '" + TextBox_Date_Finished_Termination_Refund.Text.Trim() + "', ";

            if (TextBox_Date_Second_Receipt.Enabled)
                sSql += " Date_Second_Receipt = '" + TextBox_Date_Second_Receipt.Text.Trim() + "', ";
            */
            sSql = sSql_Add_DateTime(TextBox_Date_Finished_Termination_Refund, "Date_Finished_Termination_Refund", sSql);

            if (Get_Function(Session["Flag"].ToString().Trim()) == Func.EditContractSecondPay)
            {
                // 判断当前操作的“上月锁定状态”
                if (!Common_SXD.IsLock_LockDay_LastMonth(TextBox_Date_Second_Receipt, Response))
                    sSql = sSql_Add_DateTime(TextBox_Date_Second_Receipt, "Date_Second_Receipt", sSql);

            }
            else
                sSql = sSql_Add_DateTime(TextBox_Date_Second_Receipt, "Date_Second_Receipt", sSql);
            
            
            if (Drop_Writer.Enabled)/// 下拉选项有效，用TextBox更新数据库字段
                ///sSql += " Writer = '" + Drop_Writer.SelectedItem.Text.Trim() + "', ";
                sSql += " Writer = '" + TextBox_Writer.Text.Trim() + "', ";

            if (Drop_After_Visa_US.Enabled)/// 下拉选项有效，用TextBox更新数据库字段
                ///sSql += " After_Visa_US = '" + Drop_After_Visa_US.SelectedItem.Text.Trim() + "', ";
                sSql += " After_Visa_US = '" + TextBox_After_Visa_US.Text.Trim() + "', ";

            if (Drop_Net_Applicant_US.Enabled)/// 下拉选项有效，用TextBox更新数据库字段
                ///sSql += " Net_Applicant_US = '" + Drop_Net_Applicant_US.SelectedItem.Text.Trim() + "', ";
                sSql += " Net_Applicant_US = '" + TextBox_Net_Applicant_US.Text.Trim() + "', ";

            if (TextBox_Remitter.Enabled)
                sSql += " Remitter = '" + TextBox_Remitter.Text.Trim() + "', ";

            if (TextBox_No_Origin.Enabled)
                sSql += " No_Origin = '" + TextBox_No_Origin.Text.Trim() + "', ";
            sSql = sSql_Add_TextBox(TextBox_Receipt, "Receipt", sSql);
            sSql = sSql_Add_TextBox(TextBox_Channel, "Channel", sSql);

            sSql += " Office = '" + TextBox_Office.Text.Trim() + "' ";

            sSql += " where Series_No = " + "'" + Label_Msg.Text.Trim() + "'";

            
#if MSSql
            if (Common_SXD.MSSql_ExecuteNonQuery(sSql, "", "更新数据出错：", Response))
                if (TextBox_Add_Notes.Enabled)
                    TextBox_Add_Notes.Text = "";
#elif MySql
            if (Common_SXD.MySql_ExecuteNonQuery(sSql, "", "更新数据出错：", Response))
                if (TextBox_Add_Notes.Enabled)
                    TextBox_Add_Notes.Text = "";
#endif
        }// end of Update_Contract()

        
        
        /// <summary>
        /// 确认二次付款相关的数据（不是新数据）
        /// </summary>
        /// <remarks>
        /// 总部出纳确认收款数据后的写数据库操作。
        /// </remarks>
        public void Check_SecondPayment()
        {
            //不合理收费数据与合同金额数据
            if (Is_WrongPayment())
                return;
            /*
            SqlConnection sqlCnn = new SqlConnection();
            sqlCnn.ConnectionString = strCnn;
            sqlCnn.Open(); // 建立连接
            SqlCommand sqlCmd = sqlCnn.CreateCommand(); // 创建 command 对象
            sqlCmd.CommandType = CommandType.Text; // 类型为 SQL 语句
            */

            //合同信息写入数据库
            string sSql = "Update Contract Set";
            sSql += " Pinyi = '" + TextBox_Pinyi.Text.Trim() + "', ";
            sSql += " Date_Completion_Contract = '" + TextBox_Date_Completion_Contract.Text.Trim() + "',";
            sSql += " Date_Application_Visa = '" + TextBox_Date_Application_Visa.Text.Trim() + "', ";
            //sSql += " Date_Completion_Offer = '" + TextBox_Date_Completion_Offer.Text.Trim()  + "', ";
            //sSql += " Date_Termination_Refund = '" + TextBox_Date_Termination_Refund.Text.Trim()  + "', ";
            sSql += " Termination_Refund = '" + TextBox_Termination_Refund.Text.Trim() + "', ";
            sSql += " Amount = '" + TextBox_Amount.Text.Trim() + "', ";
            sSql += " Remitter = '" + TextBox_Remitter.Text.Trim() + "', ";
            ///sSql += " Date_Second_Receipt = '" + TextBox_Date_Second_Receipt.Text.Trim() + "', ";
            sSql = sSql_Add_DateTime(TextBox_Date_Second_Receipt, "Date_Second_Receipt", sSql);
            //		sSql += " Notes = '" + TextBox_Notes.Text.Trim()  + "', ";
            string sNotes = TextBox_Notes.Text.Trim();
            if (TextBox_Add_Notes.Text.Trim().Length > 0)
            {
                sNotes += " " + TextBox_Add_Notes.Text.Trim();
                sSql += " Notes = '" + sNotes + "', ";
            }
            ///////////////////////////////

            //		sSql += " First_Payment = '" + TextBox_First_Payment.Text.Trim()  + "', ";
            sSql += " No_Origin = '" + TextBox_No_Origin.Text.Trim() + "', ";
            sSql += " Second_Payment = '" + TextBox_Second_Payment.Text.Trim() + "', ";
            sSql += " Date_Second_Payment = '" + TextBox_Date_Second_Payment.Text.Trim() + "' ";

            sSql += " where Series_No = " + "'" + Label_Msg.Text.Trim() + "'";
#if MSSql
            Common_SXD.MSSql_ExecuteNonQuery(sSql, "", "<li>更新数据出错：", Response);
#elif MySql
            Common_SXD.MySql_ExecuteNonQuery(sSql, "", "<li>更新数据出错：", Response);
#endif
           
        }

        /// <summary>
        /// 添加新合同数据
        /// </summary>
        public void Insert_NewOne()
        {
            //不合理数据
            if (Is_WrongPayment())
                return;

            ////////////////////////
            ///处理已经存在的学生名
            ////////////////////////
#if MSSql
            string sCounter = Common_SXD.CHAR_MSSQL_PLUS1("select count(Series_No) from Contract ",
                "Office like '" + TextBox_Office.Text.Trim() + "' and Student_Name like '" + TextBox_Student_Name.Text.Trim() + "'", Response);
#elif MySql
            string sCounter = Common_SXD.CHAR_MySQL_PLUS1("select count(Series_No) from Contract ",
                "Office like '" + TextBox_Office.Text.Trim() + "' and Student_Name like '" + TextBox_Student_Name.Text.Trim() + "'", Response);

#endif
            if (!CheckBox_AllowedSameName.Checked)
            {
                if (Convert.ToInt16(sCounter) > 1)
                {
                    Response.Write("<li>已经存在" + Convert.ToString((Convert.ToInt16(sCounter) - 1)).Trim() + "个‘" + TextBox_Student_Name.Text.Trim() + "’的合同！无法添加！</li>");
                    return;
                }
                else
                    Response.Clear();
            }
            else
                Response.Clear();


            //生成新合同的 "Series_No"
#if MSSql
            sSeries_No = Common_SXD.CHAR_MSSQL_PLUS1("select max(Series_No) from Contract where Series_No like '" + Session["Year_Insert"] + "%'",
                "", Response);
#elif MySql
            sSeries_No = Common_SXD.CHAR_MySQL_PLUS1("select max(Series_No) from Contract where Series_No like '" + Session["Year_Insert"] + "%'",
                "", Response);
#endif
            /*
            //在数据库中添加新的记录
            SqlConnection sqlCnn = new SqlConnection();
            sqlCnn.ConnectionString = strCnn;
            sqlCnn.Open(); // 建立连接
            SqlCommand sqlCmd = sqlCnn.CreateCommand(); // 创建 command 对象
            sqlCmd.CommandType = CommandType.Text; // 类型为 SQL 语句
            */

            DateTime time = DateTime.Now;

            //	time.ToString().Trim();
            string sSql = "insert into Contract  ( Series_No, Remitter, Date_First_Receipt, Date_First_Payment, Date_Second_Receipt, Date_Birth, Date_Completion_Offer, Date_Completion_Offer_US, Date_Second_Payment, Date_Application_Visa, Date_Completion_Contract, Date_Termination_Refund, Date_Permitting_Termination_Refund, Date_Finished_Termination_Refund, Date_Replacing_Writer, Date_Replacing_Counsellor, Office, Counsellor, Writer, After_Visa_US, Net_Applicant_US, Amount, First_Payment, Second_Payment, Termination_Refund, Student_Name, Pinyi, No_Contract, Student_Type, Destinations_OS, Channel, Receipt, Notes, No_Origin, YearMonth_Start,  Is_Active, Is_New ) values('";
            sSql += sSeries_No + "', ";
            sSql += "'" + TextBox_Remitter.Text.Trim() + "',";
            sSql += "'" + Common_SXD.TimeToYMD_Out(TextBox_Date_First_Receipt.Text.Trim()) + "',";
            sSql += "'" + Common_SXD.TimeToYMD_Out(TextBox_Date_First_Payment.Text.Trim()) + "',";
            sSql = sSql_insert_Add_DateTime( TextBox_Date_Second_Receipt, sSql);
            sSql = sSql_insert_Add_DateTime(TextBox_Date_Birth, sSql);

            ///sSql += "'" + Common_SXD.TimeToYMD(TextBox_Date_Second_Receipt.Text.Trim()) + "',";
            ///sSql += "'" + Common_SXD.TimeToYMD(TextBox_Date_Birth.Text.Trim()) + "',"; //生日
            sSql += "'1900-1-1',"; //offer完成
            sSql += "'1900-1-1',"; //美国offer完成
            sSql += "'1900-1-1',"; //二期付款
            sSql += "'1900-1-1',"; //递签
            sSql += "'1900-1-1',"; //合同完成
            sSql += "'1900-1-1',"; //退款
            sSql += "'1900-1-1',"; //批准退费日期
            sSql += "'1900-1-1',"; //完成退费日期
            sSql += "'1900-1-1',"; //更换文案日期
            sSql += "'1900-1-1',"; //更换顾问日期

            sSql += "'" + TextBox_Office.Text.Trim() + "',";
            sSql += "'" + Drop_Counsellor.SelectedItem.Text.Trim() + "',";
            //			sSql +="'" + TextBox_Writer.Text.Trim() + "',";
            sSql += "'" + Drop_Writer.SelectedItem.Text.Trim() + "', ";
            sSql += "'" + Drop_After_Visa_US.SelectedItem.Text.Trim() + "', ";
            sSql += "'" + Drop_Net_Applicant_US.SelectedItem.Text.Trim() + "', ";
            sSql += TextBox_Amount.Text.Trim() + ",";
            sSql += TextBox_First_Payment.Text.Trim() + ",";
            sSql += TextBox_Second_Payment.Text.Trim() + ",";
            sSql += TextBox_Termination_Refund.Text.Trim() + ",";

            sSql += "'" + TextBox_Student_Name.Text.Trim() + "',";
            sSql += "'" + TextBox_Pinyi.Text.Trim() + "',";
            sSql += "'" + TextBox_No_Contract.Text.Trim() + "',";

            sSql += "'" + Drop_C_Student_Type.SelectedItem.Text.Trim() + "',";
            sSql += "'" + Drop_Destinations_OS.SelectedItem.Text.Trim() + "',";

            sSql += "'" + TextBox_Channel.Text.Trim() + "',";
            sSql += "'" + TextBox_Receipt.Text.Trim() + "',";
            sSql += "'" + TextBox_Notes.Text.Trim() + "',";
            sSql += "'" + TextBox_No_Origin.Text.Trim() + "',";
            sSql += "'" + Drop_YearMonth_Start.SelectedItem.Text.Trim() + "', ";
            sSql += "1,";
            sSql += "1 )";
#if MSSql
            Common_SXD.MSSql_ExecuteNonQuery(sSql, "", "<li>更新数据出错：", Response);
#elif MySql
            Common_SXD.MySql_ExecuteNonQuery(sSql, "", "<li>更新数据出错：", Response);
#endif
           
        }

        /// <summary>
        /// 初始化： 确认退款完成
        /// </summary>
        private void Init_CheckFinishedTerminationRefund()
        {
            CheckBox_Is_New.Enabled = false;

            TextBox_Counsellor.Enabled = false;
            Drop_Counsellor.Enabled = false;
            TextBox_Writer.Enabled = false;  
            TextBox_YearMonth_Start.Enabled = false; 
            TextBox_C_Student_Type.Enabled = false; 
            TextBox_After_Visa_US.Enabled = false;
            TextBox_Net_Applicant_US.Enabled = false;
            Drop_Writer.Enabled = false; 
            Drop_YearMonth_Start.Enabled = false;
            Drop_After_Visa_US.Enabled = false;
            Drop_Net_Applicant_US.Enabled = false;
            TextBox_Student_Name.Enabled = false;
            TextBox_Pinyi.Enabled = true;
            TextBox_Date_Birth.Enabled = false;
            TextBox_Date_First_Receipt.Enabled = false;
            TextBox_Date_Second_Receipt.Enabled = false;
            TextBox_No_Contract.Enabled = false;
            TextBox_Amount.Enabled = false;
            Drop_C_Student_Type.Enabled = false;
            Drop_Destinations_OS.Enabled = false;
            TextBox_First_Payment.Enabled = false;
            TextBox_Date_First_Payment.Enabled = false;
            TextBox_Second_Payment.Enabled = false;
            TextBox_Date_Second_Payment.Enabled = false;
            TextBox_Date_Completion_Offer.Enabled = false;
            TextBox_Date_Completion_Offer_US.Enabled = false;
            TextBox_Date_Application_Visa.Enabled = false;
            TextBox_Date_Completion_Contract.Enabled = false;
            //关闭 Notes 和 Notes 添加
            TextBox_Notes.Enabled = false;
            TextBox_Add_Notes.Enabled = true;

            TextBox_Termination_Refund.Enabled = false;
            TextBox_Date_Termination_Refund.Enabled = false;
            TextBox_Date_Finished_Termination_Refund.Enabled = true;
            TextBox_Remitter.Enabled = false;

            TextBox_Date_Return_OriginalContract.Enabled = false;
            
            TextBox_Date_Second_Receipt.Enabled = false;
            TextBox_No_Origin.Enabled = false;
            TextBox_Ref_Cash_No.Enabled = false;
            //查看长字符串			TextBox_Ref_Cash_No.Enabled = false;
            TextBox_Office.Enabled = false;

            Bt_OK.Enabled = true;
            //			Bt_Reset.Disabled  = true;
            CheckBox_AllowedSameName.Enabled = false;



 
            Response.Write("<li>确认退款完成。</li>");
            /*
            SqlConnection sqlCnn = new SqlConnection(strCnn);
            // 根据传入的合同编号，生成查询 SQL 语句
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            SqlDataAdapter sqlDA = new SqlDataAdapter(sSql, sqlCnn);
            sqlDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            DataSet bsDataSet = new DataSet();
            sqlDA.Fill(bsDataSet, "Contract");
            */

            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            DataSet bsDataSet = Init_DataSet("Contract", sSql);
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行
                // 显示用户信息
                TextBox_Office.Text = rowUser["Office"].ToString().Trim();
                InitializeDrop_Counsellor(TextBox_Office.Text);
                InitializeDrop_Writer(TextBox_Office.Text);

                TextBox_Counsellor.Text = rowUser["Counsellor"].ToString().Trim();
                TextBox_Writer.Text = rowUser["Writer"].ToString().Trim();  
                TextBox_YearMonth_Start.Text = rowUser["YearMonth_Start"].ToString().Trim();
                TextBox_C_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();
                TextBox_After_Visa_US.Text = rowUser["After_Visa_US"].ToString().Trim();
                TextBox_Net_Applicant_US.Text = rowUser["Net_Applicant_US"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Counsellor"].ToString().Trim(), Drop_Counsellor);
                Common_SXD.SetSelectedIndex(rowUser["Writer"].ToString().Trim(), Drop_Writer);
                Common_SXD.SetSelectedIndex(rowUser["YearMonth_Start"].ToString().Trim(), Drop_YearMonth_Start);
                Common_SXD.SetSelectedIndex(rowUser["After_Visa_US"].ToString().Trim(), Drop_After_Visa_US);
                Common_SXD.SetSelectedIndex(rowUser["Net_Applicant_US"].ToString().Trim(), Drop_Net_Applicant_US);
                TextBox_Student_Name.Text = rowUser["Student_Name"].ToString().Trim();

                TextBox_Date_Completion_Offer.Text = rowUser["Date_Completion_Offer"].ToString().Trim();
                TextBox_Date_Completion_Offer.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer.Text);

                TextBox_Date_Completion_Offer_US.Text = rowUser["Date_Completion_Offer_US"].ToString().Trim();
                TextBox_Date_Completion_Offer_US.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer_US.Text);

                TextBox_Date_Application_Visa.Text = rowUser["Date_Application_Visa"].ToString().Trim();
                TextBox_Date_Application_Visa.Text = Common_SXD.TimeToYMD(TextBox_Date_Application_Visa.Text);

                TextBox_Date_Completion_Contract.Text = rowUser["Date_Completion_Contract"].ToString().Trim();
                TextBox_Date_Completion_Contract.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Contract.Text);


                TextBox_Termination_Refund.Text = rowUser["Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = rowUser["Date_Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Termination_Refund.Text);

                TextBox_Date_Finished_Termination_Refund.Text = rowUser["Date_Finished_Termination_Refund"].ToString().Trim();
                TextBox_Date_Finished_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Finished_Termination_Refund.Text);



                //		TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                //		string sTemp.Format(TextBox_Date_Birth.Text, "{0:yyyy-MM-dd}");
                TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                TextBox_Date_Birth.Text = Common_SXD.TimeToYMD(TextBox_Date_Birth.Text);

                TextBox_Pinyi.Text = rowUser["Pinyi"].ToString().Trim();
                TextBox_No_Contract.Text = rowUser["No_Contract"].ToString().Trim();
                //		TextBox_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();

                Common_SXD.SetSelectedIndex(rowUser["Student_Type"].ToString().Trim(), Drop_C_Student_Type);
                Common_SXD.SetSelectedIndex(rowUser["Destinations_OS"].ToString().Trim(), Drop_Destinations_OS);


                TextBox_Remitter.Text = rowUser["Remitter"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = rowUser["Date_Second_Receipt"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_Second_Receipt.Text);

                TextBox_Notes.Text = rowUser["Notes"].ToString().Trim();
                TextBox_Ref_Cash_No.Text = rowUser["Ref_Cash_No"].ToString().Trim();


                TextBox_Amount.Text = rowUser["Amount"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = rowUser["Date_First_Receipt"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_First_Receipt.Text);

                TextBox_First_Payment.Text = rowUser["First_Payment"].ToString().Trim();
                TextBox_Second_Payment.Text = rowUser["Second_Payment"].ToString().Trim();
                TextBox_Date_First_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_First_Payment"].ToString().Trim());
                TextBox_Date_Second_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_Second_Payment"].ToString().Trim());


                Display_CheckBox_Deduct_FreeService();

                /*
                /////////////零中介退费后，显示是否扣奖选项
                Regex Deduct = new Regex("(Deduct)|(deduct)");
                if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
                {
                    if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                        (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                    {
                        CheckBox_Deduct_FreeService.Visible = true;
                        if (Deduct.IsMatch(TextBox_Notes.Text))
                        {
                            CheckBox_Deduct_FreeService.Checked = true;
                        }
                        else
                            CheckBox_Deduct_FreeService.Checked = false;
                    }
                    else
                        CheckBox_Deduct_FreeService.Visible = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;
                */

                CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                /////////////////////////////////////////////////////////////////////////////////////

                if ((rowUser["Is_New"].ToString().Trim() == "True") ||
                    (rowUser["Is_New"].ToString().Trim() == "1"))
                    CheckBox_Is_New.Checked = true;
                else
                    CheckBox_Is_New.Checked = false;

            }
            ///sqlCnn.Close();

        }


        /// <summary>
        /// 初始化： 确认一期款到账
        /// </summary>
        private void Init_CheckContractFirstPay()
        {
            CheckBox_Is_New.Enabled = true;

            TextBox_Counsellor.Enabled = false;
            Drop_Counsellor.Enabled = false;
            TextBox_Writer.Enabled = false;  
            TextBox_YearMonth_Start.Enabled = false; 
            TextBox_C_Student_Type.Enabled = false;
            TextBox_After_Visa_US.Enabled = false;
            TextBox_Net_Applicant_US.Enabled = false;

            Drop_Writer.Enabled = false; 
            Drop_YearMonth_Start.Enabled = false;
            Drop_After_Visa_US.Enabled = false;
            Drop_Net_Applicant_US.Enabled = false;
            TextBox_Student_Name.Enabled = false;
            TextBox_Pinyi.Enabled = true;
            TextBox_Date_Birth.Enabled = false;
            TextBox_Date_First_Receipt.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_First_Receipt);
            TextBox_No_Contract.Enabled = true;
            TextBox_Amount.Enabled = true;
            Drop_C_Student_Type.Enabled = false;
            Drop_Destinations_OS.Enabled = false;

            TextBox_Second_Payment.Enabled = true;
            TextBox_Date_Second_Payment.Enabled = true;
            TextBox_Date_Completion_Offer.Enabled = false;
            TextBox_Date_Completion_Offer_US.Enabled = false;
            TextBox_Date_Application_Visa.Enabled = false;
            TextBox_Date_Completion_Contract.Enabled = false;
            //关闭Notes，打开 Notes 添加			
            TextBox_Notes.Enabled = false;
            TextBox_Add_Notes.Enabled = true;

            TextBox_Termination_Refund.Enabled = false;
            TextBox_Date_Termination_Refund.Enabled = false;
            TextBox_Date_Finished_Termination_Refund.Enabled = false;

            TextBox_Date_Second_Receipt.Enabled = true;



            //查看长字符串			TextBox_Ref_Cash_No.Enabled = false;
            TextBox_Office.Enabled = false;
            TextBox_No_Origin.Enabled = false;

            Bt_OK.Enabled = true;
            // Bt_Reset.Disabled  = true;

            Response.Write("<li>确认一期款。</li>");
            /*
            SqlConnection sqlCnn = new SqlConnection(strCnn);
            // 根据传入的合同编号，生成查询 SQL 语句
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            SqlDataAdapter sqlDA = new SqlDataAdapter(sSql, sqlCnn);
            sqlDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            DataSet bsDataSet = new DataSet();
            sqlDA.Fill(bsDataSet, "Contract");
            */

            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            DataSet bsDataSet = Init_DataSet("Contract", sSql);
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行
                // 显示用户信息
                TextBox_Office.Text = rowUser["Office"].ToString().Trim();
                InitializeDrop_Counsellor(TextBox_Office.Text);
                InitializeDrop_Writer(TextBox_Office.Text);

                TextBox_Counsellor.Text = rowUser["Counsellor"].ToString().Trim();
                TextBox_Writer.Text = rowUser["Writer"].ToString().Trim();  
                TextBox_YearMonth_Start.Text = rowUser["YearMonth_Start"].ToString().Trim();
                TextBox_C_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();
                TextBox_After_Visa_US.Text = rowUser["After_Visa_US"].ToString().Trim();
                TextBox_Net_Applicant_US.Text = rowUser["Net_Applicant_US"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Counsellor"].ToString().Trim(), Drop_Counsellor);
                Common_SXD.SetSelectedIndex(rowUser["Writer"].ToString().Trim(), Drop_Writer);
                Common_SXD.SetSelectedIndex(rowUser["YearMonth_Start"].ToString().Trim(), Drop_YearMonth_Start);
                Common_SXD.SetSelectedIndex(rowUser["After_Visa_US"].ToString().Trim(), Drop_After_Visa_US);
                Common_SXD.SetSelectedIndex(rowUser["Net_Applicant_US"].ToString().Trim(), Drop_Net_Applicant_US);
                TextBox_Student_Name.Text = rowUser["Student_Name"].ToString().Trim();

                TextBox_Date_Completion_Offer.Text = rowUser["Date_Completion_Offer"].ToString().Trim();
                TextBox_Date_Completion_Offer.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer.Text);

                TextBox_Date_Completion_Offer_US.Text = rowUser["Date_Completion_Offer_US"].ToString().Trim();
                TextBox_Date_Completion_Offer_US.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer_US.Text);

                TextBox_Date_Application_Visa.Text = rowUser["Date_Application_Visa"].ToString().Trim();
                TextBox_Date_Application_Visa.Text = Common_SXD.TimeToYMD(TextBox_Date_Application_Visa.Text);

                TextBox_Date_Completion_Contract.Text = rowUser["Date_Completion_Contract"].ToString().Trim();
                TextBox_Date_Completion_Contract.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Contract.Text);

                TextBox_Channel.Text = rowUser["Channel"].ToString().Trim();
                TextBox_Receipt.Text = rowUser["Receipt"].ToString().Trim();

                TextBox_Termination_Refund.Text = rowUser["Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = rowUser["Date_Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Termination_Refund.Text);

                TextBox_Date_Finished_Termination_Refund.Text = rowUser["Date_Finished_Termination_Refund"].ToString().Trim();
                TextBox_Date_Finished_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Finished_Termination_Refund.Text);



                //		TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                //		string sTemp.Format(TextBox_Date_Birth.Text, "{0:yyyy-MM-dd}");
                TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                TextBox_Date_Birth.Text = Common_SXD.TimeToYMD(TextBox_Date_Birth.Text);

                TextBox_Pinyi.Text = rowUser["Pinyi"].ToString().Trim();
                TextBox_No_Contract.Text = rowUser["No_Contract"].ToString().Trim();
                //		TextBox_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();

                Common_SXD.SetSelectedIndex(rowUser["Student_Type"].ToString().Trim(), Drop_C_Student_Type);
                Common_SXD.SetSelectedIndex(rowUser["Destinations_OS"].ToString().Trim(), Drop_Destinations_OS);


                TextBox_Remitter.Text = rowUser["Remitter"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = rowUser["Date_Second_Receipt"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_Second_Receipt.Text);

                TextBox_Notes.Text = rowUser["Notes"].ToString().Trim();
                TextBox_Ref_Cash_No.Text = rowUser["Ref_Cash_No"].ToString().Trim();


                TextBox_Amount.Text = rowUser["Amount"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = rowUser["Date_First_Receipt"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_First_Receipt.Text);

                TextBox_First_Payment.Text = rowUser["First_Payment"].ToString().Trim();
                TextBox_Second_Payment.Text = rowUser["Second_Payment"].ToString().Trim();
                TextBox_Date_First_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_First_Payment"].ToString().Trim());
                TextBox_Date_Second_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_Second_Payment"].ToString().Trim());


                TextBox_Date_Return_OriginalContract.Text = Common_SXD.TimeToYMD(rowUser["Date_Return_OriginalContract"].ToString().Trim());

                Display_CheckBox_Deduct_FreeService();
                /*
                /////////////零中介退费后，显示是否扣奖选项 
                Regex Deduct = new Regex("(Deduct)|(deduct)");
                if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
                {
                    if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                        (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                    {
                        CheckBox_Deduct_FreeService.Visible = true;
                        if (Deduct.IsMatch(TextBox_Notes.Text))
                        {
                            CheckBox_Deduct_FreeService.Checked = true;
                        }
                        else
                            CheckBox_Deduct_FreeService.Checked = false;
                    }
                    else
                        CheckBox_Deduct_FreeService.Visible = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;
                */
                CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                /////////////////////////////////////////////////////////////////////////////////////

                ///如果Date_First_Payment日期为空，允许修改"一期款日期"
   /*             if (TextBox_Date_First_Payment.Text.ToString().Trim() != "")
                {
                    if (Convert.ToDateTime(TextBox_Date_First_Payment.Text) < Convert.ToDateTime("1930-1-1"))
                        TextBox_Date_First_Payment.Enabled = true;
                    else
                        TextBox_Date_First_Payment.Enabled = false;
                }
                else
                    TextBox_Date_First_Payment.Enabled = true;
   */             
                TextBox_Date_First_Payment.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_First_Payment);

                ///只有 joanna bai 可以修改"合同原件返回日期"
                ///如果Date_Return_OriginalContract日期为空，允许修改"合同原件返回日期"
                ///&& Session["Email"].ToString().ToLower().Trim() != "joanna_bai"
                ///
                if (Session["Email"].ToString().Trim().ToLower() == "joanna_bai")
                {
                    if (TextBox_Date_Return_OriginalContract.Text.ToString().Trim() != "")
                    {
                        if (Convert.ToDateTime(TextBox_Date_Return_OriginalContract.Text) < Convert.ToDateTime("1930-1-1"))
                            TextBox_Date_Return_OriginalContract.Enabled = true;
                        else
                            TextBox_Date_Return_OriginalContract.Enabled = false;
                    }
                    else
                        TextBox_Date_Return_OriginalContract.Enabled = true;
                }
                else
                    TextBox_Date_Return_OriginalContract.Enabled = false;

                if ((rowUser["Is_New"].ToString().Trim() == "True") ||
                    (rowUser["Is_New"].ToString().Trim() == "1"))
                    CheckBox_Is_New.Checked = true;
                else
                    CheckBox_Is_New.Checked = false;

            }
            ///sqlCnn.Close();

        }

        /// <summary>
        /// 初始化：修改“二期付款、退款、合同执行情况”的网页。
        /// </summary>
        private void Init_EditContractSecondPay()
        {
            bool bIs_Admin = Convert.ToBoolean(Session["Is_Admin"]);
            bool bIs_O_M = Convert.ToBoolean(Session["Is_O_M"]);
            bool bIs_Collector = Convert.ToBoolean(Session["Is_Collector"]);
            bool bIs_Accountant = Convert.ToBoolean(Session["Is_Accountant"]);
            bool bIs_Receptionist = Convert.ToBoolean(Session["Is_Receptionist"]);
            bool bIs_Writer = Convert.ToBoolean(Session["Is_Writer"]);
            bool bIs_Counsellor = Convert.ToBoolean(Session["Is_Counsellor"]);

            Response.Write("<li>修改：二期付款、退款、合同执行情况。</li>");
            /*
            SqlConnection sqlCnn = new SqlConnection(strCnn);
            // 根据传入的合同编号，生成查询 SQL 语句
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            SqlDataAdapter sqlDA = new SqlDataAdapter(sSql, sqlCnn);
            sqlDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            DataSet bsDataSet = new DataSet();
            sqlDA.Fill(bsDataSet, "Contract");
            */
            
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            DataSet bsDataSet = Init_DataSet("Contract", sSql);
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行
                // 显示用户信息
                TextBox_Office.Text = rowUser["Office"].ToString().Trim();
                InitializeDrop_Counsellor(TextBox_Office.Text);
                InitializeDrop_Writer(TextBox_Office.Text);

                TextBox_Counsellor.Text = rowUser["Counsellor"].ToString().Trim();
                TextBox_Writer.Text = rowUser["Writer"].ToString().Trim();  
                TextBox_YearMonth_Start.Text = rowUser["YearMonth_Start"].ToString().Trim();
                TextBox_C_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();
                TextBox_After_Visa_US.Text = rowUser["After_Visa_US"].ToString().Trim();
                TextBox_Net_Applicant_US.Text = rowUser["Net_Applicant_US"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Counsellor"].ToString().Trim(), Drop_Counsellor);
                Common_SXD.SetSelectedIndex(rowUser["Writer"].ToString().Trim(), Drop_Writer);
                Common_SXD.SetSelectedIndex(rowUser["YearMonth_Start"].ToString().Trim(), Drop_YearMonth_Start);
                Common_SXD.SetSelectedIndex(rowUser["After_Visa_US"].ToString().Trim(), Drop_After_Visa_US);
                Common_SXD.SetSelectedIndex(rowUser["Net_Applicant_US"].ToString().Trim(), Drop_Net_Applicant_US);

                TextBox_Student_Name.Text = rowUser["Student_Name"].ToString().Trim();

                TextBox_Date_Completion_Offer.Text = rowUser["Date_Completion_Offer"].ToString().Trim();
                TextBox_Date_Completion_Offer.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer.Text);

                TextBox_Date_Completion_Offer_US.Text = rowUser["Date_Completion_Offer_US"].ToString().Trim();
                TextBox_Date_Completion_Offer_US.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer_US.Text);

                TextBox_Date_Application_Visa.Text = rowUser["Date_Application_Visa"].ToString().Trim();
                TextBox_Date_Application_Visa.Text = Common_SXD.TimeToYMD(TextBox_Date_Application_Visa.Text);

                TextBox_Date_Completion_Contract.Text = rowUser["Date_Completion_Contract"].ToString().Trim();
                TextBox_Date_Completion_Contract.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Contract.Text);


                TextBox_Termination_Refund.Text = rowUser["Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = rowUser["Date_Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Termination_Refund.Text);

                TextBox_Date_Finished_Termination_Refund.Text = rowUser["Date_Finished_Termination_Refund"].ToString().Trim();
                TextBox_Date_Finished_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Finished_Termination_Refund.Text);



                //		TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                //		string sTemp.Format(TextBox_Date_Birth.Text, "{0:yyyy-MM-dd}");
                TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                TextBox_Date_Birth.Text = Common_SXD.TimeToYMD(TextBox_Date_Birth.Text);

                TextBox_Pinyi.Text = rowUser["Pinyi"].ToString().Trim();
                TextBox_No_Contract.Text = rowUser["No_Contract"].ToString().Trim();
                TextBox_No_Origin.Text = rowUser["No_Origin"].ToString().Trim();
                TextBox_Receipt.Text = rowUser["Receipt"].ToString().Trim();
                TextBox_Channel.Text = rowUser["Channel"].ToString().Trim();
                
                Common_SXD.SetSelectedIndex(rowUser["Student_Type"].ToString().Trim(), Drop_C_Student_Type);
                Common_SXD.SetSelectedIndex(rowUser["Destinations_OS"].ToString().Trim(), Drop_Destinations_OS);


                TextBox_Remitter.Text = rowUser["Remitter"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = rowUser["Date_Second_Receipt"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_Second_Receipt.Text);

                TextBox_Notes.Text = rowUser["Notes"].ToString().Trim();
                TextBox_Ref_Cash_No.Text = rowUser["Ref_Cash_No"].ToString().Trim();


                TextBox_Amount.Text = rowUser["Amount"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = rowUser["Date_First_Receipt"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_First_Receipt.Text);

                TextBox_First_Payment.Text = rowUser["First_Payment"].ToString().Trim();
                TextBox_Second_Payment.Text = rowUser["Second_Payment"].ToString().Trim();
                TextBox_Date_First_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_First_Payment"].ToString().Trim());
                TextBox_Date_Second_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_Second_Payment"].ToString().Trim());

                if ((rowUser["Is_New"].ToString().Trim() == "True") ||
                    (rowUser["Is_New"].ToString().Trim() == "1"))
                    CheckBox_Is_New.Checked = true;
                else
                    CheckBox_Is_New.Checked = false;

            }
            ///sqlCnn.Close();

            CheckBox_Is_New.Enabled = false;

            //遇到问号或英文名，打开文案字段的修改功能
            Regex Question = new Regex("([？]{1,}|[?]{1,})");
            Regex English = new Regex("([a-zA-Z]{1,})");

            if (Question.IsMatch(TextBox_Writer.Text) || English.IsMatch(TextBox_Writer.Text))
            {//文案
                //TextBox_Writer.Enabled = true;
                TextBox_Writer.Enabled = false;  
                TextBox_YearMonth_Start.Enabled = false; 
                TextBox_C_Student_Type.Enabled = false;
                Drop_Writer.Enabled = true;

            }
            else
            {
                TextBox_Writer.Enabled = false;  
                TextBox_YearMonth_Start.Enabled = false; 
                TextBox_C_Student_Type.Enabled = false;
                Drop_Writer.Enabled = false; 
            }

            if (Question.IsMatch(TextBox_After_Visa_US.Text) || English.IsMatch(TextBox_After_Visa_US.Text))
            {// 美国签证后续
                TextBox_After_Visa_US.Enabled = false;            
                Drop_After_Visa_US.Enabled = true;
            }
            else
            {
                TextBox_After_Visa_US.Enabled = false;
                Drop_After_Visa_US.Enabled = false;       
            }

            if (Question.IsMatch(TextBox_Net_Applicant_US.Text) || English.IsMatch(TextBox_Net_Applicant_US.Text))
            {// 美国网络申请
                TextBox_Net_Applicant_US.Enabled = false;
                Drop_Net_Applicant_US.Enabled = true;
            }
            else
            {
                TextBox_Net_Applicant_US.Enabled = false;
                Drop_Net_Applicant_US.Enabled = false;
            }
            
            //遇到问号或英文名，打开顾问字段的修改功能, 地区经理，打开顾问修改权限
            TextBox_Counsellor.Enabled = false;
            if (Question.IsMatch(TextBox_Counsellor.Text) ||
                English.IsMatch(TextBox_Counsellor.Text) || bIs_O_M)
            {
                //TextBox_Counsellor.Enabled = true;
                Drop_Counsellor.Enabled = true;
            }
            else
            {
                //TextBox_Counsellor.Enabled = false;
                Drop_Counsellor.Enabled = false;
            }

            //////////////////////////////////////////////////////////////////////////////////////////////
            TextBox_Student_Name.Enabled = false;

            TextBox_Pinyi.Enabled = true;
            Regularexpressionvalidator_Pinyi.Enabled = false;

            TextBox_Date_Birth.Enabled = true;
            TextBox_Date_First_Receipt.Enabled = false;
            
            /// 二期款开收据日期，只允许一次性修改。
            TextBox_Date_Second_Receipt.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_Second_Receipt);

//            if ( (Session["Office"].ToString().Trim() == "上海" && Session["Email"].ToString().ToLower().Trim() == "joanna_bai0" )
//                || Question.IsMatch(TextBox_No_Contract.Text) || TextBox_No_Contract.Text == "" ) 
            /// 上海办公室暂时开放权限
            if (Question.IsMatch(TextBox_No_Contract.Text) || TextBox_No_Contract.Text == "") 
            {/// 问号或者空白，允许修改。
                TextBox_No_Contract.Enabled = true;
            }
            else
            {
                TextBox_No_Contract.Enabled = false;
            }


            TextBox_Amount.Enabled = true;
            Drop_C_Student_Type.Enabled = false;
            Drop_Destinations_OS.Enabled = false;
            TextBox_First_Payment.Enabled = false;
            TextBox_Date_First_Payment.Enabled = false;

            TextBox_Date_Return_OriginalContract.Enabled = false;

            //二期款金额
            if (Convert.ToDouble(TextBox_Second_Payment.Text) <= 0.0)
                TextBox_Second_Payment.Enabled = true;
            else
                TextBox_Second_Payment.Enabled = false;
            //			TextBox_Second_Payment.Enabled = true;

            TextBox_Date_Second_Payment.Enabled = false;

            string sStudent_Type = Drop_C_Student_Type.SelectedItem.Text.ToString();
            string sDestinations_OS = Drop_Destinations_OS.SelectedItem.Text.ToString();
            
            // 收到offers时间
            switch (TextBox_Office.Text)
            {
                 /*				case "南京": //暂时开放 2009-6-26以前的数据	
                                case "上海":
                //				case "北京":
                //				case "杭州":
                //				case "宁波":
                //				case "武汉":
                //				case "重庆":
                //				case "成都":
                //				case "广州":
                //				case "青岛":
                                    if( TextBox_Date_Completion_Offer.Text.ToString().Trim() != "")
                                    {
                                        if (Convert.ToDateTime(TextBox_Date_Completion_Offer.Text) < Convert.ToDateTime("2009-6-26") )
                                            TextBox_Date_Completion_Offer.Enabled = true;
                                        else 
                                            TextBox_Date_Completion_Offer.Enabled = false;
                                    }
                                    else
                                    {
                                        TextBox_Date_Completion_Offer.Enabled = true;
                                    }

                                    break;

                */
                    
                default: //正常设置的权限
                    if (sStudent_Type == "签证" || sStudent_Type == "凯业签证"   ||
                        ((sStudent_Type == "全程一次" || sStudent_Type == "全程二次" || sStudent_Type == "申请学校") && sDestinations_OS == "美国") )
                    {
                        TextBox_Date_Completion_Offer.Enabled = false;
                    }
                    else if (TextBox_Date_Completion_Offer.Text.ToString().Trim() != "")
                    {
                        if (Convert.ToDateTime(TextBox_Date_Completion_Offer.Text) < Convert.ToDateTime("1930-1-1"))
                            TextBox_Date_Completion_Offer.Enabled = true;
                        else
                            TextBox_Date_Completion_Offer.Enabled = false;
                    }
                    else
                    {
                        TextBox_Date_Completion_Offer.Enabled = true;
                    }
                    break;
            }

            // 收到美国offers时间
            switch (TextBox_Office.Text)
            {
                /*				case "南京": //暂时开放 2009-6-26以前的数据	
                               case "上海":
               //				case "北京":
               //				case "杭州":
               //				case "宁波":
               //				case "武汉":
               //				case "重庆":
               //				case "成都":
               //				case "广州":
               //				case "青岛":
                                   if( TextBox_Date_Completion_Offer.Text.ToString().Trim() != "")
                                   {
                                       if (Convert.ToDateTime(TextBox_Date_Completion_Offer.Text) < Convert.ToDateTime("2009-6-26") )
                                           TextBox_Date_Completion_Offer.Enabled = true;
                                       else 
                                           TextBox_Date_Completion_Offer.Enabled = false;
                                   }
                                   else
                                   {
                                       TextBox_Date_Completion_Offer.Enabled = true;
                                   }

                                   break;

               */

                default: //正常设置的权限
                    Regex Included_US = new Regex("(美)");
                    Regex Included_CA = new Regex("(加)");
                    Regex Quancheng = new Regex("(全程)");
                    if ( ( Quancheng.IsMatch(sStudent_Type) || sStudent_Type == "申请学校" || sStudent_Type == "联办" ) &&
                        ( Included_US.IsMatch(sDestinations_OS) || Included_CA.IsMatch(sDestinations_OS) )
                        )
                    {
                        if (TextBox_Date_Completion_Offer_US.Text.ToString().Trim() != "")
                        {
                            if (Convert.ToDateTime(TextBox_Date_Completion_Offer_US.Text) < Convert.ToDateTime("1930-1-1"))
                                TextBox_Date_Completion_Offer_US.Enabled = true;
                            else
                                TextBox_Date_Completion_Offer_US.Enabled = false;
                        }
                        else
                        {
                            TextBox_Date_Completion_Offer_US.Enabled = true;
                        }
                        
                    }
                    else 
                    {
                        TextBox_Date_Completion_Offer_US.Enabled = false;
                    }
                    
                    break;
            }



            // 递签时间
            //			if( TextBox_Office.Text == "北京" )
            //				if( Convert.ToDateTime(TextBox_Date_Application_Visa.Text) < Convert.ToDateTime("1930-1-1") )
            TextBox_Date_Application_Visa.Enabled = true;
            //				else 
            //					TextBox_Date_Application_Visa.Enabled = false;
            //			else  //  暂时开放 2009-6-26以前的数据
            //				if( Convert.ToDateTime(TextBox_Date_Application_Visa.Text) < Convert.ToDateTime("2009-6-26") )
            //					TextBox_Date_Application_Visa.Enabled = true;
            //				else 
            //					TextBox_Date_Application_Visa.Enabled = false;
            //			TextBox_Date_Application_Visa.Enabled = true;

            //合同完成时间
            if (bIs_O_M || Session["Email"].ToString() == "joanna_bai0") //允许小陈修改合同完成时间
            {
                if (TextBox_Date_Completion_Contract.Text.ToString().Trim() != "")
                {
                    if (Convert.ToDateTime(TextBox_Date_Completion_Contract.Text) < Convert.ToDateTime("1930-1-1"))
                        TextBox_Date_Completion_Contract.Enabled = true;
                    else
                        TextBox_Date_Completion_Contract.Enabled = false;
                }
                else
                {
                    TextBox_Date_Completion_Contract.Enabled = true;
                }
            }
            else
                TextBox_Date_Completion_Contract.Enabled = false;

            //			TextBox_Date_Completion_Contract.Enabled = true;
            //关闭 Notes， 打开 Notes 添加			
            TextBox_Notes.Enabled = false;
            TextBox_Add_Notes.Enabled = true;

            TextBox_Termination_Refund.Enabled = true;

            //退费时间
            if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
            {
                if (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) < Convert.ToDateTime("1930-1-1"))
                    TextBox_Date_Termination_Refund.Enabled = true;
                else
                    TextBox_Date_Termination_Refund.Enabled = false;
            }
            else
                TextBox_Date_Termination_Refund.Enabled = true;

            //退费金额
            if (Convert.ToDouble(TextBox_Termination_Refund.Text) <= 0.0)
                TextBox_Termination_Refund.Enabled = true;
            else
                TextBox_Termination_Refund.Enabled = false;

            Display_CheckBox_Deduct_FreeService();
            
            /// 一期款开收据日期，只允许一次性修改。
            TextBox_Date_First_Receipt.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_First_Receipt);
            TextBox_Date_First_Receipt.Enabled = true;

            /// 二期款开收据日期，只允许一次性修改。
            TextBox_Date_Second_Receipt.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_Second_Receipt);
            
            ///TextBox_Date_Second_Receipt.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_Second_Receipt);


            /*
            /////////////零中介退费后，显示是否扣奖选项
            Regex Deduct = new Regex("(Deduct)|(deduct)");
            //			if(TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
            //			{
            if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
            {

                if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                    (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                {
                    CheckBox_Deduct_FreeService.Visible = true;
                    if (Deduct.IsMatch(TextBox_Notes.Text))
                    {
                        CheckBox_Deduct_FreeService.Checked = true;
                    }
                    else
                        CheckBox_Deduct_FreeService.Checked = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;

            }
            else
            {
                //			}
                //			else
                //				CheckBox_Deduct_FreeService.Visible = false;
                //只有 O_M 能修改 Deduct 选项
                //			if(bIs_O_M && !Deduct.IsMatch(TextBox_Notes.Text) )
                //			{
                CheckBox_Deduct_FreeService.Enabled = true;
                //			}
                //			else
                //				CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                /////////////////////////////////////////////////////////////////////////////////////
            }
             */ 
            //完成退费时间
            TextBox_Date_Finished_Termination_Refund.Enabled = false;

            TextBox_Remitter.Enabled = true;
            TextBox_Date_Second_Receipt.Enabled = true;

            TextBox_Date_Return_OriginalContract.Enabled = false;
            
            //查看长字符串			
            TextBox_Ref_Cash_No.Enabled = false;
            TextBox_Office.Enabled = false;

            Bt_OK.Enabled = true;
            //			Bt_Reset.Disabled  = true;


        }

        /// <summary>
        ///  初始化：确认二次付款相关的数据（不是新数据）
        /// </summary>
        private void Init_CheckContractSecondPay()
        {
            CheckBox_Is_New.Enabled = false;

            TextBox_Counsellor.Enabled = false;
            Drop_Counsellor.Enabled = false;
            TextBox_Writer.Enabled = false;  
            TextBox_YearMonth_Start.Enabled = false; 
            TextBox_C_Student_Type.Enabled = false;
            TextBox_After_Visa_US.Enabled = false;
            TextBox_Net_Applicant_US.Enabled = false;

            Drop_Writer.Enabled = false; 
            Drop_YearMonth_Start.Enabled = false;
            Drop_After_Visa_US.Enabled = false;
            Drop_Net_Applicant_US.Enabled = false;

            TextBox_Student_Name.Enabled = false;
            TextBox_Pinyi.Enabled = true;
            TextBox_Date_Birth.Enabled = false;
            TextBox_Date_First_Receipt.Enabled = false;

            /// 二期款开收据日期，只允许一次性修改。
            TextBox_Date_Second_Receipt.Enabled = Is_Allowed_OnceEdit_Date(TextBox_Date_Second_Receipt);
            
            TextBox_No_Contract.Enabled = false;
            TextBox_Amount.Enabled = true;
            Drop_C_Student_Type.Enabled = false;
            Drop_Destinations_OS.Enabled = false;
            TextBox_First_Payment.Enabled = false;
            TextBox_Date_First_Payment.Enabled = false;
            TextBox_Second_Payment.Enabled = true;
            TextBox_Date_Second_Payment.Enabled = true;
            TextBox_Date_Completion_Offer.Enabled = false;
            TextBox_Date_Completion_Offer_US.Enabled = false;
            TextBox_Date_Application_Visa.Enabled = false;
            TextBox_Date_Completion_Contract.Enabled = false;
            //关闭 Notes， 打开 Notes 添加			
            TextBox_Notes.Enabled = false;
            TextBox_Add_Notes.Enabled = true;

            TextBox_Termination_Refund.Enabled = false;
            TextBox_Date_Termination_Refund.Enabled = false;
            TextBox_Date_Finished_Termination_Refund.Enabled = false;

            // TextBox_Remitter.Enabled = false;
            TextBox_Date_Second_Receipt.Enabled = false;

            TextBox_Date_Return_OriginalContract.Enabled = false;
            
            //查看长字符串			TextBox_Ref_Cash_No.Enabled = false;
            TextBox_Office.Enabled = false;
            TextBox_No_Origin.Enabled = false;

            Bt_OK.Enabled = true;
            // Bt_Reset.Disabled  = true;

            Response.Write("<li>确认二期款。</li>");
            
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
            DataSet bsDataSet = Init_DataSet("Contract", sSql);
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行
                // 显示用户信息
                TextBox_Office.Text = rowUser["Office"].ToString().Trim();
                InitializeDrop_Counsellor(TextBox_Office.Text);
                InitializeDrop_Writer(TextBox_Office.Text);

                TextBox_Counsellor.Text = rowUser["Counsellor"].ToString().Trim();
                TextBox_Writer.Text = rowUser["Writer"].ToString().Trim();  
                TextBox_YearMonth_Start.Text = rowUser["YearMonth_Start"].ToString().Trim();
                TextBox_C_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();
                TextBox_After_Visa_US.Text = rowUser["After_Visa_US"].ToString().Trim();
                TextBox_Net_Applicant_US.Text = rowUser["Net_Applicant_US"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Counsellor"].ToString().Trim(), Drop_Counsellor);
                Common_SXD.SetSelectedIndex(rowUser["Writer"].ToString().Trim(), Drop_Writer);
                Common_SXD.SetSelectedIndex(rowUser["YearMonth_Start"].ToString().Trim(), Drop_YearMonth_Start);
                Common_SXD.SetSelectedIndex(rowUser["After_Visa_US"].ToString().Trim(), Drop_After_Visa_US);
                Common_SXD.SetSelectedIndex(rowUser["Net_Applicant_US"].ToString().Trim(), Drop_Net_Applicant_US);
                TextBox_Student_Name.Text = rowUser["Student_Name"].ToString().Trim();

                TextBox_Date_Completion_Offer.Text = rowUser["Date_Completion_Offer"].ToString().Trim();
                TextBox_Date_Completion_Offer.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer.Text);

                TextBox_Date_Completion_Offer_US.Text = rowUser["Date_Completion_Offer_US"].ToString().Trim();
                TextBox_Date_Completion_Offer_US.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Offer_US.Text);

                TextBox_Date_Application_Visa.Text = rowUser["Date_Application_Visa"].ToString().Trim();
                TextBox_Date_Application_Visa.Text = Common_SXD.TimeToYMD(TextBox_Date_Application_Visa.Text);

                TextBox_Date_Completion_Contract.Text = rowUser["Date_Completion_Contract"].ToString().Trim();
                TextBox_Date_Completion_Contract.Text = Common_SXD.TimeToYMD(TextBox_Date_Completion_Contract.Text);

                TextBox_Channel.Text = rowUser["Channel"].ToString().Trim();
                TextBox_Receipt.Text = rowUser["Receipt"].ToString().Trim();

                TextBox_Termination_Refund.Text = rowUser["Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = rowUser["Date_Termination_Refund"].ToString().Trim();
                TextBox_Date_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Termination_Refund.Text);

                TextBox_Date_Finished_Termination_Refund.Text = rowUser["Date_Finished_Termination_Refund"].ToString().Trim();
                TextBox_Date_Finished_Termination_Refund.Text = Common_SXD.TimeToYMD(TextBox_Date_Finished_Termination_Refund.Text);



                //		TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                //		string sTemp.Format(TextBox_Date_Birth.Text, "{0:yyyy-MM-dd}");
                TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                TextBox_Date_Birth.Text = Common_SXD.TimeToYMD(TextBox_Date_Birth.Text);

                TextBox_Pinyi.Text = rowUser["Pinyi"].ToString().Trim();
                TextBox_No_Contract.Text = rowUser["No_Contract"].ToString().Trim();
                //		TextBox_Student_Type.Text = rowUser["Student_Type"].ToString().Trim();

                Common_SXD.SetSelectedIndex(rowUser["Student_Type"].ToString().Trim(), Drop_C_Student_Type);
                Common_SXD.SetSelectedIndex(rowUser["Destinations_OS"].ToString().Trim(), Drop_Destinations_OS);


                TextBox_Remitter.Text = rowUser["Remitter"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = rowUser["Date_Second_Receipt"].ToString().Trim();
                TextBox_Date_Second_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_Second_Receipt.Text);

                TextBox_Notes.Text = rowUser["Notes"].ToString().Trim();
                TextBox_Ref_Cash_No.Text = rowUser["Ref_Cash_No"].ToString().Trim();


                TextBox_Amount.Text = rowUser["Amount"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = rowUser["Date_First_Receipt"].ToString().Trim();
                TextBox_Date_First_Receipt.Text = Common_SXD.TimeToYMD(TextBox_Date_First_Receipt.Text);

                TextBox_First_Payment.Text = rowUser["First_Payment"].ToString().Trim();
                TextBox_Second_Payment.Text = rowUser["Second_Payment"].ToString().Trim();
                TextBox_Date_First_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_First_Payment"].ToString().Trim());
                TextBox_Date_Second_Payment.Text = Common_SXD.TimeToYMD(rowUser["Date_Second_Payment"].ToString().Trim());

                Display_CheckBox_Deduct_FreeService();
                /*
                /////////////零中介退费后，显示是否扣奖选项
                Regex Deduct = new Regex("(Deduct)|(deduct)");
                if (TextBox_Date_Termination_Refund.Text.ToString().Trim() != "")
                {
                    if (Drop_C_Student_Type.SelectedItem.Text.ToString() == "零中介" &&
                        (Convert.ToDateTime(TextBox_Date_Termination_Refund.Text) > Convert.ToDateTime("1930-1-1")))
                    {
                        CheckBox_Deduct_FreeService.Visible = true;
                        if (Deduct.IsMatch(TextBox_Notes.Text))
                        {
                            CheckBox_Deduct_FreeService.Checked = true;
                        }
                        else
                            CheckBox_Deduct_FreeService.Checked = false;
                    }
                    else
                        CheckBox_Deduct_FreeService.Visible = false;
                }
                else
                    CheckBox_Deduct_FreeService.Visible = false;
                */

                CheckBox_Deduct_FreeService.Enabled = false; // 不能修改 Deduct 选项
                /////////////////////////////////////////////////////////////////////////////////////

                if ((rowUser["Is_New"].ToString().Trim() == "True")||
                    (rowUser["Is_New"].ToString().Trim() == "1"))
                    CheckBox_Is_New.Checked = true;
                else
                    CheckBox_Is_New.Checked = false;

            }
            ///sqlCnn.Close();

        }

        protected void Drop_Writer_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_Writer.Text = Drop_Writer.SelectedItem.Text.ToString().Trim();

        }

        protected void Drop_Net_Applicant_US_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_Net_Applicant_US.Text = Drop_Net_Applicant_US.SelectedItem.Text.ToString().Trim();
        }

        protected void Drop_After_Visa_US_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_After_Visa_US.Text = Drop_After_Visa_US.SelectedItem.Text.ToString().Trim();
        }
        
        protected void Drop_YearMonth_Start_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_YearMonth_Start.Text = Drop_YearMonth_Start.SelectedItem.Text.ToString().Trim();
        }

        protected void Drop_C_Student_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_C_Student_Type.Text = Drop_C_Student_Type.SelectedItem.Text.ToString().Trim();
        }

        protected void Drop_Counsellor_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_Counsellor.Text = Drop_Counsellor.SelectedItem.Text.ToString().Trim();
        }

    }
}
